ChambeRFienD Posted April 7, 2006 Share Posted April 7, 2006 How would I go about finding the difference between a date stored in the 'DATE' type in a MySQL database and the current date.. Just looking for how many days there are between the current date and what is stored in the database. Link to comment https://forums.phpfreaks.com/topic/6779-finding-the-difference-in-date/ Share on other sites More sharing options...
drewbee Posted April 7, 2006 Share Posted April 7, 2006 [!--quoteo(post=362432:date=Apr 6 2006, 11:30 PM:name=ChambeRFienD)--][div class=\'quotetop\']QUOTE(ChambeRFienD @ Apr 6 2006, 11:30 PM) [snapback]362432[/snapback][/div][div class=\'quotemain\'][!--quotec--]How would I go about finding the difference between a date stored in the 'DATE' type in a MySQL database and the current date.. Just looking for how many days there are between the current date and what is stored in the database.[/quote]is it in timestamp?try this: // mysql timestamp from db$old_timestamp = $row['date'];// Time in seconds from then to right now$elapsed_seconds = time() - $old_timestamp;// divide by 60 for minutes, 60 for hours, then 24 for days, using floor to make an integer$elapsed_days = floor(($elapsed_seconds / 60) / 60 / 24); Link to comment https://forums.phpfreaks.com/topic/6779-finding-the-difference-in-date/#findComment-24664 Share on other sites More sharing options...
skhale Posted April 7, 2006 Share Posted April 7, 2006 [quote]DATEDIFF(expr,expr2)DATEDIFF() returns the number of days between the start date expr and the end date expr2. expr and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.mysql> SELECT DATEDIFF('1997-12-31 23:59:59','1997-12-30'); -> 1mysql> SELECT DATEDIFF('1997-11-30 23:59:59','1997-12-31'); -> -31DATEDIFF() was added in MySQL 4.1.1[/quote] Link to comment https://forums.phpfreaks.com/topic/6779-finding-the-difference-in-date/#findComment-24666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.