Jump to content

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.