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

select given month from date field

Status
Not open for further replies.

Shrp

IS-IT--Management
Jan 9, 2002
82
US
Given records containing a date field, how do you select
all records where the month portion of the date equals a
given month? Same with the date portion equaling a
given date?

Thanks!
 
Most data base systems provide some function to extract the year/month/date portions from a date value, such as SELECT *
FROM mytable
WHERE month(mydatefield) = wantedmonth

There should be further functions to select year(mydatefield) and day(mydatefield) .

Hope this helps

milan432
 
What DBMS? In Sybase, use datepart(month, datefield).

Greg.
 
This is ODBC accessing Access. Thanks!
 
I recommend posting Access query questions in forum701, "Microsoft: Access Queries and JET SQL." Access JETS SQL differs from ANSI SQL in many ways.

Either Month(datecol) or datepart("mm",datecol) will return the numeric value of the month. You may want to consider adding "Year" to the selection criteria if the tables contains multiple years of data. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
I also checked the help inside Access, and it lists
DatePart("m",datefield) as the way to go.

I try a:

SELECT * from xxx where DatePart("m",datefield) = 'Mar'

...and I get an "Internal Server Error". I'm using IIS.
 
Datepart("m",[date]) returns a number not a string.

Use format(date(),"mmm") to return a 3 character month name. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top