JakeSilver Posted December 15, 2008 Share Posted December 15, 2008 Hi There, Im am trying to creat a little script that displays the months/years of 12 months previous to a specific unix time code. I am having real difficulty trying to figure out the logic. For example say there is a unix time code of 1226102400 or (11 November 2008) I would like it to display the following:- 2007 November October September August July June May April March Febuary January 2008 December November Obviously depending on the UNIX tim code depends on the months/years that are displayed. I have the following code at the moment: $curmonth achived from the unix time code. $curmonth=date("m", $f->date); if($curmonth > $lowmonth){ echo "$months[$curmonth]<br>"; echo $lowmonth; $lowmonth == $curmonth; echo $lowmonth; Can anyone help or offer a solution to my problem. I am aware that the code i have created is rubbish and is no where near able to do the job. Any help would be greatfully apprciated. Jake Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/ Share on other sites More sharing options...
JakeSilver Posted December 15, 2008 Author Share Posted December 15, 2008 I have found this function. function get_months($date1, $date2) { $time1 = strtotime($date1); $time2 = strtotime($date2); $my = date('mY', $time2); $months = array(date('F', $time1)); $f = ''; while($time1 < $time2) { $time1 = strtotime((date('Y-m-d', $time1).' +15days')); if(date('F', $time1) != $f) { $f = date('F', $time1); if(date('mY', $time1) != $my && ($time1 < $time2)) $months[] = date('F', $time1); } } $months[] = date('F', $time2); return $months; } and also included: $first=date('Y-m-d',$datefetch->date); $last=date('Y-m-d',$datemonthlow->date); print_r(get_months('$first', '$last')); however this displays the following "Array ( [0] => January [1] => January ) " and doesn't display the actual months? Any ideas why? Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/#findComment-715842 Share on other sites More sharing options...
JakeSilver Posted December 15, 2008 Author Share Posted December 15, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/#findComment-716125 Share on other sites More sharing options...
JakeSilver Posted December 16, 2008 Author Share Posted December 16, 2008 Surely someone must have created something like this before? Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/#findComment-716578 Share on other sites More sharing options...
gevans Posted December 16, 2008 Share Posted December 16, 2008 hows this <?php $tstamp = time(); $year = date("Y",$tstamp); $month = date("n",$tstamp); echo $year.'<br />'; for($i=0;$i<12;$i++){ echo date("F", mktime(0, 0, 0, $month, 0, $year)).'<br />'; if($month === 12){ echo '<br /><br />'.++$year.'<br />'; } $month++; } ?> Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/#findComment-716586 Share on other sites More sharing options...
JakeSilver Posted December 16, 2008 Author Share Posted December 16, 2008 Thankyou so much! I really appreciate that! works like a treat! Link to comment https://forums.phpfreaks.com/topic/137055-unix-code-calander/#findComment-716592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.