johnsmith153 Posted November 6, 2010 Share Posted November 6, 2010 I need to work out the months remaining of someone's membership when the date provied is in the format dd/mm/YYYY - rounded down to one month. So, today being Nov 6th if the membership expired on 10th Feb then this would return 3. 1st Feb would be 2 etc.. Link to comment https://forums.phpfreaks.com/topic/217969-simple-date-calc/ Share on other sites More sharing options...
mike12255 Posted November 6, 2010 Share Posted November 6, 2010 Do you have the date entered into a database? Link to comment https://forums.phpfreaks.com/topic/217969-simple-date-calc/#findComment-1131182 Share on other sites More sharing options...
litebearer Posted November 6, 2010 Share Posted November 6, 2010 Perhaps... <?PHP function MonthDiff($start_date, $end_date) { $array01 = explode("/", $start_date); $array02 = explode("/", $end_date); $start_date2 = $array01[1] . "/" . $array01[0] . "/" . $array01[2]; $end_date2 = $array02[1] . "/" . $array02[0] . "/" . $array02[2]; $ts1=strtotime($start_date2); $ts2=strtotime($end_date2); $m_diff = floor(($ts2-$ts1)/2628000); return $m_diff; } $start_date = "06/11/2010"; $end_date = "10/02/2011"; echo MonthDiff($start_date, $end_date); $end_date = "01/02/2011"; echo "<br>"; echo MonthDiff($start_date, $end_date); ?> Link to comment https://forums.phpfreaks.com/topic/217969-simple-date-calc/#findComment-1131202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.