Select day from date field in SQL table


I have a date field in my SQL table
I have tried this and it works perfectly.

sql = "SELECT * FROM mytable WHERE MONTH(mydate)=3 AND YEAR(mydate)=2005"

But when I try this, i tells me there is a syntax error.  Why?  How to rectify?

sql = "SELECT * FROM mytable WHERE DAY(my_date)= 27"

I'm totally puzzled since I read from tutorials that you can use the DAY function to rerieve the day from date.
limhodavAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
What version of MySQL do you use vs which version of the documentation did you read?
Day() It is available as of MySQL 4.1.1.

you might try to use DAYOFMONTH(date) instead
0
 
limhodavAuthor Commented:
Thanks a million. I used DayofMonth and it worked immediately.!!!! Have been wrecking my brains so hard for a solution and it's actually that simple.  Didn't know bout the existence of this function.

Btw, I'm using SQL version 3.2. Perhaps, the version is too low to be able to use the date() function.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Btw, I'm using SQL version 3.2. Perhaps, the version is too low to be able to use the date() function.

as noted:
Day() It is available as of MySQL 4.1.1.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.