[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1950
  • Last Modified:

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.
0
limhodav
Asked:
limhodav
  • 2
1 Solution
 
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now