Bendude14 Posted August 11, 2008 Share Posted August 11, 2008 Can someone point me in the right direction for subtracting one date from another 11/08/2008 - 05/04/2008 = Number of days between these two dates? eg 128 days Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/ Share on other sites More sharing options...
bluejay002 Posted August 11, 2008 Share Posted August 11, 2008 If you are not to do it SQL, then you can do it by converting both dates to a timestamp, then deduct then convert into days. example: <?php $date1 = '2008-02-05'; $date2 = '2008-03-05'; $secsInDay = 60 * 60 * 24; $secsInterval = strtotime($date2) - strtotime($date1); $daysInterval = $secsInterval / $secsInDay; echo $daysInterval; ?> Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/#findComment-613270 Share on other sites More sharing options...
Bendude14 Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks for that i will give it a go. I do have SQL available if there is an easier way using the database? ben Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/#findComment-613281 Share on other sites More sharing options...
bluejay002 Posted August 11, 2008 Share Posted August 11, 2008 definitely... and i do recommend it than using PHP for this kind of stuff. this is possible using DATEDIFF() example: ... DATEDIFF(field_date_one, field_date_two) ... the result will always be in days jay, Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/#findComment-613288 Share on other sites More sharing options...
Bendude14 Posted August 11, 2008 Author Share Posted August 11, 2008 Thanks just what i needed Ben Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/#findComment-613308 Share on other sites More sharing options...
bluejay002 Posted August 12, 2008 Share Posted August 12, 2008 your welcome Link to comment https://forums.phpfreaks.com/topic/119104-solved-subtracting-dates/#findComment-614298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.