Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get last day of the month 1

Status
Not open for further replies.

mbwmbk

Programmer
Dec 12, 2002
19
0
0
US
Hi All,
I have this question:
dim mth1, mth2
dim yr1, yr2
suppose:
mth1=1, yr1=2001
mth2=5, yr2=2003

How can I get the last day of the month given mth1=1 (January)?
how to retrieve all the records from table ndata where
ndate > 1/1/2001 and ndate < 5/31/2003?

thanks.

 
Hi,

Try this...Idea is to get the first date of next month and subtract 1 day from it... hope it helps

Dim strLastDate
strLastdate = cdate(month(datevalue)+ 1 & &quot;/&quot; & &quot;1/&quot; & year(datevalue)) -1

Sunil
 
Though, make sure to account for december month + 1 = 13

Here's what I wrote a while back...
if (v-month + 1) <> 13 then
assign v-lastday = date(v-month + 1,1,v-fullyear) - 1.
else
assign v-lastday = date(1,1,v-fullyear + 1) - 1.
Jessica [ponytails2]
 
Try this...

<%
dim mth1, mth2
dim yr1, yr2

mth1=1
yr1=2001
mth2=5
yr2=2003

'Create the dates in a date format
dim date1
date1 = CDate(&quot;1/1/&quot;&CStr(yr1))
date1 = DateAdd(&quot;m&quot;, mth1-1, date1)

dim date2
date2 = CDate(&quot;1/1/&quot;&CStr(yr2))
date2 = DateAdd(&quot;m&quot;, mth2, date2)
date2 = DateAdd(&quot;d&quot;, -1, date2)

'Now create your statement for Access database
AccessQuery = &quot;SELECT * FROM ndata BETWEEN #&quot;&date1&&quot;# AND #&quot;&date2&&quot;#&quot;
response.write(AccessQuery)
'Or create your statement for SQL database
SQLQuery = &quot;SELECT * FROM ndata BETWEEN '&quot;&date1&&quot;' AND '&quot;&date2&&quot;'&quot;
response.write(&quot;<BR><BR>&quot;&SQLQuery)
%> BDC.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top