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