SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    563
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    time / date calculation

    Hi,

    Why there's difference between the following ?

    PHP Code:
    <?php
    $days 
    8;

    $strdate mktime (0,0,0,10,27,2013);
    $end_mk mktime (0,0,0,10, (27 $days), 2013);

    $end_ti $strdate + ($days 24 60 60);

    echo 
    "Days to Add: " $days "<br />\n";
    echo 
    "Start Date via mktime: " date("d-m-Y"$strdate) . "<br />\n";
    echo 
    "End Date via mktime: " date("d-m-Y"$end_mk) . "<br />\n";
    echo 
    "End Date via time: " date("d-m-Y"$end_ti) . "<br />\n";
    ?>
    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    DST.

  3. #3
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    563
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ginerjm View Post
    DST.
    Hi,

    You mean to say that mktime calculates correctly and multiplication does'nt ?

    Thanks.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Apparently so. If you change your test dates to Sept or Apr or May it all works. Only Oct fails. Doing a search I found that 11/3/13 is the day we change time in US, so that's it.

    Also - if you read the manual for mktime, one of the notes is quite specific about NOT using seconds arithmetic to modify dates. Doesn't explain why, but apparently you're not the first to discover this hole.

  5. #5
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    563
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Hmm, i had thought about DST but then someone told me that it only effects just an hour, so I stopped thinking about it. But now I reliazed that mktime is much efficient at all this.

    Thanks.

  6. #6
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,307
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I messed round with this problem a while ago:

    http://www.sitepoint.com/forums/show...hem&highlight=

    The function I wrote worked fine I think. Also what
    PHP Guru talked about looks good.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •