DelphiFAQ Home Search:

Compare 2 dates in mysql


comments4 comments. Current rating: 3 stars (1 votes). Leave comments and/ or rate it.


I need to compare 2 dates in mysql but I only have version 3.23 of mysql installed and cannot upgrade.


With mysql 4.1.1 the function datediff(date1,date2) and others were introduced.

If you are using 4.0 or older, you need to use to_days(date1) and subtract in this form:

select TO_DAYS(NOW()) - TO_DAYS(last_modification)
from mytable;


2006-09-01, 03:03:22
anonymous from India  
hey its not date_diff, its datediff(date1, date2) in the latest versions of mysql...
2009-03-24, 01:30:17
anonymous from Singapore  
thanks, really needed to find out how to calculate the date diff for older sql version but most guides online is teaching datediff which is only supported in the newer version of mysql.
2009-03-27, 06:44:18
anonymous from India  
very good my son ,carry on....
2009-04-29, 11:55:05
anonymous from Lesotho  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: