• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

where datediff

New Here ,
Aug 26, 2007 Aug 26, 2007

Copy link to clipboard

Copied

Gday i have a query which i want to select all where date is 28 days old

but i cant get it working, can someone tell me what is wrong with my code?

TOPICS
Advanced techniques

Views

317

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Aug 26, 2007 Aug 26, 2007
Well it turns out in MySQL that it is Now() to get the current date, so what you wrote originally would have worked if you had used the correct syntax for dateDiff().

Check this for all the date time functions:-
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Here what is what you need:-
DATEDIFF(Now(),InDate) >= 28

Votes

Translate

Translate
Engaged ,
Aug 26, 2007 Aug 26, 2007

Copy link to clipboard

Copied

Remember that cfquery is putting a string together to send to the database so DATEDIFF(d,InDate,Now()) is wrong it should be DATEDIFF(d,InDate,#Now()#). However, depending on what db you are using I would recommend that you use the internal time on the database so on SQL Server you would use DATEDIFF(d,InDate,getDate())

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 26, 2007 Aug 26, 2007

Copy link to clipboard

Copied

hi yes i tried that already but i get this error

Syntax error or access violation: 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 'getDate()) >= 28' at line 3

any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 26, 2007 Aug 26, 2007

Copy link to clipboard

Copied

LATEST
Well it turns out in MySQL that it is Now() to get the current date, so what you wrote originally would have worked if you had used the correct syntax for dateDiff().

Check this for all the date time functions:-
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Here what is what you need:-
DATEDIFF(Now(),InDate) >= 28

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation