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

Date function Beginning of Year to Now

Status
Not open for further replies.

camelk

Technical User
Mar 19, 2002
26
US
I have a query in which I want to retrieve all the records from the beginning of the year to date (i.e., all the records from 01/01/02 thru 04/11/02). But, I want the query to be able to do this in forth coming years (i.e., on 03/03/03 retrieve all the records from 01/01/03 thru 03/03/03. How do I do this? Thanks!
 
SELECT * FROM MyTable WHERE MyDateField Between DateSerial(Year(Date()),1,1) And Date();

Aivars
 
Use this as the criteria for the date field.


Between Format(("01/01/" & Year(Date())),"Short Date") And Format(Date(),"Short Date")


I used "Short Date" as the Format but if your date values are in a different format you will have to change either the existing date value formats or the above statement. Either way the criteria must match the format of the dates being selected.

Regards
Rod
 
Thanks. I used Rod's code and it worked well.
camelk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top