 |
| Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

October 7th, 2004, 05:32 PM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to get a month's beg. and ending dates
Hi Vijay & all,
Vijay first of all thanks for many of your solutions.I need your help again.
I want to get the beg and ending dates for the last month based upon todays date.here is what i have written.
d=date()
Response.write "Todays Date is" & CDate(d)
k=Day(CDate(d))
REsponse.write "No. of days to go back is " & k
k=k-1
end1=DateAdd("d", -k, d)
REsponse.write "end1 is" & end1
sat=Month(end1) & "/" & Day(end1) & "/" & Year(end1)
Response.write" month beg" & sat
|
|

October 7th, 2004, 08:26 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hello,
You said, you want to get beg and end dates for the last month based on the current date. But your code seems for current month only. What exactly your requirement?
If simply getting beg date of a month is always first la.
Your code seems you need to display number days back .. thats ok.
end date means months end date or you have any calculation to be done to get the end date?
Make it clear.
-----------
Rajani
|
|

October 7th, 2004, 10:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi widad,
There are many ways to achieving this. Here is one of those. Try changing the commented ThisDate with different values.
Code:
<%
ThisDate = date()
'ThisDate = "08/03/2004" 'Feb 8th 2004
EndDate = dateadd("d",-day(date()),ThisDate)
BegDate = dateadd("d",-day(EndDate)+1,EndDate)
Response.write "LastMonth: " & "<BR>" & BegDate & "<BR>" & EndDate
%>
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

October 8th, 2004, 03:30 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
DateSerial function is your best friend here I think.
General syntax is dateVar = DateSerial(year, month, day), but the best thing about this function is that it accepts 0 as the day and interprets that as the last day of the previous month. (It also accepts 0 as month and interprets that as last month of previous year.)
EndDate = DateSerial(year(date()), month(date()), 0)
BegDate = DateSerial(year(date()), month(date())-1, 1)
hth
Phil
|
|

October 8th, 2004, 09:26 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks guys.It works.
|
|

October 8th, 2004, 08:52 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Thats great to know Phil. So far I didn't even mind to have a look at DataSerial().
Cheers!
_________________________
- Vijay G
Strive for Perfection
|
|

October 20th, 2004, 07:19 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Gretings to all. I am new in this forum
Thanks to Phil. I never knew this functionality of DateSerial()
Anubhav Kumar
|
|
 |