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

How do you convert a date to year only? 1

Status
Not open for further replies.

djgolds

Technical User
Dec 11, 2000
23
US
I have a column in my table that is in date format example 01/25/2001. I'd like to convert this date to year only to do various queries. Even though I put my format as yyyy in the query, when it does the filtering, it returns numerous instances for the same year becase it still recognizes the date as 01/25/2001 rather than just 2001. Any help would be appreciated. Thanks!
 
Sometimes you need to create a seperate column, for example:

Yr: Format(YourDateField, "yyyy")

Now you can put criteria in this column like 1999, or 2000, and it should filter properly.

Let us know if I am not understanding you correctly.

Can you post the SQL part of you query? Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
That's it! Turn off the "show" for the sort/parameter row.

Here's a question:

format(myDate,"yyyy")

DatePart("yyyy",myDate)

Which is more efficient?

 
Not Sure? Let's add one more

Format(myDate,"yyyy")

DatePart("yyyy",myDate)

Year(myDate)

I would think that they would all be close to the same as each function must evaluate a date. My guess is the last one may be a little more efficient because after evaluating the date, it does not have to format it, it simply returns the year. Just a hunch however. If anyone else knows, please jump in. Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top