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

Datepart function 1

Status
Not open for further replies.

mok44

MIS
Sep 3, 2002
36
US
I want to exclude in my query any record with a date prior to the current month. I used [<datepart(&quot;m&quot;, date())] which worked fine for all previous months until I hit January. I suppose when Dec (ie 12) is compared to Jan (01) my statement does not work anymore. Any ideas? Thanks.
 
You can either build the date for the first of the month using DateSerial() and compare to your date or use the Format(datefield,&quot;yyyymm&quot;) function on your date and Now() and then compare the results.

 
use DateDiff :

datediff(&quot;m&quot;,date1,date2)=0 AND datediff(&quot;yyyy&quot;,date1,date2) = 0

returns records which have the same month and year value
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top