php - timeword - from one date to another date -


rewritten clearer

i have website has several exhibits. 1 exhibit can span on number of days , months. in sense can span years (although that's if starts in previous year , ends in current year 25th december 2010 5th january 2011)

what need function take 2 dates, , display in human readable format least amount of information required interpret.

some examples:

so given dates 18th may 2010 19th may 2010, should displayed as: 18 19th may 2010. notice here, first date has month , year ommitted because same final date.

16th april 2011 15th may 2011 = 16th april 15th may 2011 notice here year omitted, same reason above.

8th march 2008 8th march 2009 = 8th march 2008 8th march 2009 notice here there no change because there different year need display all.

=============================================================

it needs intelligently , helpfully hide parts of dates can deduced reading scentence.

psuedo function:

timeworddatefromto(date1, date2, 'd m y'){  $showyear = $showmonth = true; if(year(date1)==year(date2))  { $showyear = false if(month(date1)==month(date2)) $showmonth = false }  //do else here  } 

thanks

alright should work, other person stated need add error checking. assumed had dates "15th april 2011" , "18th may 2011" inputs. code use cleanup to.

function sentencefromdates($date1, $date2){ $string=false; $date1= strtotime($date1); $date2= strtotime($date2);   //first check years $year1= date('y', $date1); $year2= date('y', $date2); $month1= date('n', $date1); $month2= date('n', $date2);     //different years, no change     if($year2 > $year1)     {          $string= date('js m y', $date1) . ' ' . date('js m y', $date2);         return $string;     }     //same year , month     elseif($month1 == $month2)     {         // 15th 20th may 2011         $string= date('js', $date1) . ' ' . date('js m y', $date2);         return $string;      }     //same year different month     else     {         $string= date('js m', $date1) . ' ' . date('js m y', $date2);         return $string;     } 

}


Comments