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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Dates Month and Day only

Status
Not open for further replies.

girky

Programmer
Oct 24, 2002
72
US
I have two dates date1 and date2 in mm/dd/yyyy format in a table. I need to find if date2 occurs between date1 and one week after date1. I don't know how to compair based on month and day only. Can anyone help?
Thanks!
 
If you want to see that date2 is within 7 days of date1, then you need to be concerned about the year also. In that case, this should work:

Code:
<%date1 = cdate(&quot;11/30/2003&quot;)
date2 = cdate(&quot;12/1/2003&quot;)

if date2 >= date1 and date2 <= date1 + 7 then
	Response.Write &quot;Yes&quot;
else
	Response.Write &quot;No&quot;
end if%>


mwa
<><
 
Sorry, I wasn't very clear. I wanted to see if date2 was within a week of date1 regardless of the year. But I did find something that seems to work

date2 = Month(Rec1(&quot;date2&quot;))&&quot;/&quot;&Day(Rec1(&quot;date2&quot;))
date2 = cDate(date2)

gives me date2 but put it in this year instead of the year that it was, which seems to work b/c date1 is always close to today's date.

Thanks for your help
 
use the datediff function

Returns the number of intervals between two dates.

DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])
The DateDiff function syntax has these parts:

Arguments

interval
Required. String expression that is the interval you want to use to calculate the differences between date1 and date2. See Settings section for values.

date1, date2
Required. Date expressions. Two dates you want to use in the calculation.

firstdayofweek
Optional. Constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values.

firstweekofyear
Optional. Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. See Settings section for values.



example
datediff(&quot;d&quot;,&quot;1/1/2003&quot;,&quot;1/12/2003&quot;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top