FramezArt Posted February 22, 2008 Share Posted February 22, 2008 I have an insert record form that has 2 fields: One for the FROM date, and the other for the TO date. When I display them I get the basic formatting that looks like this: 12/01/2008 - 12/03/2008 What i want is to have them display like this: December 01 - 03, 2008 Is this possible? Please Help! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/ Share on other sites More sharing options...
drisate Posted February 22, 2008 Share Posted February 22, 2008 Use something like this $date=explode("/", $from) if ($date[0]=="01"){$date[0]="September";} [...] echo "$date[0] $date[1], $date[2]" Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-473937 Share on other sites More sharing options...
obsidian Posted February 22, 2008 Share Posted February 22, 2008 I have an insert record form that has 2 fields: One for the FROM date, and the other for the TO date. When I display them I get the basic formatting that looks like this: 12/01/2008 - 12/03/2008 You would be much better off using a MySQL DATE datatype to store your dates. You can easily do calculations on it that way, but in the meantime, try something like this: <?php $start = '12/01/2008'; $end = '12/03/2008'; echo date('F j, Y', strtotime($start)), '-', date('F j, Y', strtotime($end)); ?> Obviously, this isn't exactly what you're after, but it will work for spans covering multiple months, and you can easily figure out your logic from here. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-473982 Share on other sites More sharing options...
Bauer418 Posted February 22, 2008 Share Posted February 22, 2008 As somewhat of an extension to obsidian's solution, you could do something such as: <?php $start = strtotime('12/01/2008'); $end = strtotime('12/03/2008'); if (date('FY', $start) == date('FY', $end)) { echo date('F j', $start), ' - ', date('j, Y', $end); } else { echo date('F j, Y', $start), ' - ', date('F j, Y', $end); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-473990 Share on other sites More sharing options...
FramezArt Posted February 22, 2008 Author Share Posted February 22, 2008 Thanks So Much! I used this: $data = "$row_rsActAnn[dateFrom]-$row_rsActAnn[dateTo]"; list($dateFromYear, $dateFromMonth, $dateFromDay, $dateToYear, $dateToMonth, $dateToDay) = explode("-", $data); if ($dateFromMonth =="01") { $dateFromMonth = "January"; } if ($dateFromMonth =="02") { $dateFromMonth = "February"; } [...] echo "$dateFromMonth $dateFromDay - $dateToDay , $dateFromYear"; and it worked great! Thanks so much for your help! K Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-474025 Share on other sites More sharing options...
drisate Posted February 23, 2008 Share Posted February 23, 2008 Always glad to help :-) Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-474204 Share on other sites More sharing options...
Bauer418 Posted February 23, 2008 Share Posted February 23, 2008 Thanks So Much! I used this: $data = "$row_rsActAnn[dateFrom]-$row_rsActAnn[dateTo]"; list($dateFromYear, $dateFromMonth, $dateFromDay, $dateToYear, $dateToMonth, $dateToDay) = explode("-", $data); if ($dateFromMonth =="01") { $dateFromMonth = "January"; } if ($dateFromMonth =="02") { $dateFromMonth = "February"; } [...] Not to get picky at you, but it may be more logical to set an array of $months, such as: $months = array(1 => 'January', 2 => 'February', 3 => 'March' ...); And then later in the script you can check $months[$dateFromMonth]. Instead of having lines and lines of if statements (relatively inefficient). Also, you're aware that this will only handles Quote Link to comment https://forums.phpfreaks.com/topic/92496-i-need-help-creating-a-date-range-with-a-specific-display-result/#findComment-474536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.