xwishmasterx Posted October 7, 2011 Share Posted October 7, 2011 Hello I have a timestamp formated as : "2011-10-20 12:37:21" I need to show days left till this date (disregard the hours, minutes, seconds..), so I'll end up with 'there is "X" days left untill' I really cannot figure you all this date/time stuff, but hopefully this is not to difficult :-\ Anyone got a "quick" code for this? Link to comment https://forums.phpfreaks.com/topic/248660-time-show-days-left-to-a-timestamp/ Share on other sites More sharing options...
The Little Guy Posted October 7, 2011 Share Posted October 7, 2011 I created this function in a class I will be releasing soon (which I am excited about). But this subtracts 2 dates and gives you the number of days. function datediff($start_date, $end_date, $exact = false){ if(!is_int($start_date)){ if((bool)$exact) $start = strtotime($start_date); else $start = strtotime(date("Y-m-d", strtotime($start_date))); }else{ $start = $start_date; } if(!is_int($end_date)){ if((bool)$exact) $end = strtotime($end_date); else $end = strtotime(date("Y-m-d", strtotime($end_date))); }else{ $end = $end_date; } return ($start - $end) / 60 / 60 / 24; } Link to comment https://forums.phpfreaks.com/topic/248660-time-show-days-left-to-a-timestamp/#findComment-1277073 Share on other sites More sharing options...
xwishmasterx Posted October 7, 2011 Author Share Posted October 7, 2011 that's a great thing, but I'm not really understanding where my timestamp should be added here..never really dealt with these functions before.. Link to comment https://forums.phpfreaks.com/topic/248660-time-show-days-left-to-a-timestamp/#findComment-1277078 Share on other sites More sharing options...
The Little Guy Posted October 7, 2011 Share Posted October 7, 2011 echo datediff("2011-10-20 12:37:21", date("Y-m-d")); Link to comment https://forums.phpfreaks.com/topic/248660-time-show-days-left-to-a-timestamp/#findComment-1277099 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.