Jump to content

Recommended Posts

I can never seem to get the date function to work:

SELECT *, DATE_FORMAT(`datetime`, '%W, %M %D') AS `date`, DATE_FORMAT(`datetime`, '%l:%i %p') AS `time` FROM `table` WHERE `a` IS NULL AND DATE_FORMAT(`datetime`, '%Y') = '$year' AND DATE(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC

Here's the mysql_error():
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC' at line 1

I don't see a problem.
I'm using MySQL 5.0.21
Link to comment
https://forums.phpfreaks.com/topic/15149-date-function/
Share on other sites

This isn't the first time I've gotten "SQL error" things when the SQL was fine. It happened before and I don't know why. Interpolation? I am confused what you mean.

And what's wrong with naming it datetime? I never name my columns according to their type, except for datetime. The php never uses $row['datetime']. I just split the datetime up to date and time using SQL. What else would I name it, and why would it matter?
Link to comment
https://forums.phpfreaks.com/topic/15149-date-function/#findComment-63171
Share on other sites

[quote author=johnnyk link=topic=101248.msg400446#msg400446 date=1153405332]
I can never seem to get the date function to work:

SELECT *, DATE_FORMAT(`datetime`, '%W, %M %D') AS `date`, DATE_FORMAT(`datetime`, '%l:%i %p') AS `time` FROM `table` WHERE `a` IS NULL AND DATE_FORMAT(`datetime`, '%Y') = '$year' AND DATE(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC

Here's the mysql_error():
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(`datetime`) >= '2006-07-20' ORDER BY `datetime` ASC' at line 1

I don't see a problem.
I'm using MySQL 5.0.21
[/quote]
If that's the exact query you ran then I can only assume that your version of MYSQL is actually lower than 4.1. The syntax error you posted would be caused by the fact that the DATE function only became available in version 4.1.1 if that is the case.

Run the query below using the same script to verify the version.
[code]
SELECT VERSION();
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15149-date-function/#findComment-63216
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.