Jump to content

confused about mktime


mrplatts

Recommended Posts

I've written a script to set up calendar for a six-day rotating schedule.  With some help here, I've written the code to get it basically working. 

here's my issue:

I assign a date using
[code]
$s = mktime (0,0,0,$sm, $sd, $sy); 
[/code]

Then display it using
[code]
print date('Y-m-d',$s);
[/code]

The timestamp that prints in the next column when I display

[code]
echo '<td>'.$s.'</td>';
[/code]

Is alwas exactly one hour off, Is there some sort of correction I need to do for DST? In fact, when I check it agains unixtimestamp.com. it is always a different date that appears.

Oh, additionally, after about two months of dates a date repeats.  (I'm adding 86400 to increment one day.)

Sample output:
2006-08-24 Thursday1156392000
2006-08-25 Friday   1156478400
2006-08-26 Saturday156564800
2006-08-27 Sunday 1156651200
2006-08-28 Monday 1156737600


Very grateful for your input!

Rich
Link to comment
https://forums.phpfreaks.com/topic/27181-confused-about-mktime/
Share on other sites

Instead of adding 86400, add 1 to the day value before passing to mktime().  mktime() will compensate for ends of months, ends of years and daylight savings, and generally do what you want it to do.

Take a look at the comments in the online manual for more tips.

http://sg.php.net/manual/en/function.date.php
http://sg.php.net/manual/en/function.mktime.php
Link to comment
https://forums.phpfreaks.com/topic/27181-confused-about-mktime/#findComment-124302
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.