StrToTime () issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pjotr Wedersteers

    StrToTime () issue

    I'm using strtotime to get the timestamp for midnight. I have a statistics
    script for my pagecounter that displays hits since midnight.
    I also display the number of hours and minutes passed since midnight.

    $start = strtotime ('today 00:00');
    $timepassed = date ('H:i', time () - $start);

    The weird part is at 11.30 AM it says 12 hrs and 30 minutes have passed.
    I tried adding GMT+1 like so: $start = strtotime ('today 00:00 GMT+1');
    because I suspect the fact I'm in Holland is the reason for the
    miscalculation.
    But this format is refused by strtotime. (-1)
    Does anyone know
    a) whether this is indeed the problem, and
    b) how to fix it. Preferrably not alone for me here, but in suc a way anyone
    around the globe would have a correctly working script if they'd use mine.

    The php page for strtotime pointed me to a link at gnu.org where the syntax
    for it apparantly is listed, but I get a no such page error.
    TIA!
    Pjotr


  • Berislav Lopac

    #2
    Re: StrToTime () issue

    Pjotr Wedersteers wrote:[color=blue]
    > I'm using strtotime to get the timestamp for midnight. I have a
    > statistics script for my pagecounter that displays hits since
    > midnight.
    > I also display the number of hours and minutes passed since midnight.
    >
    > $start = strtotime ('today 00:00');
    > $timepassed = date ('H:i', time () - $start);
    >
    > The weird part is at 11.30 AM it says 12 hrs and 30 minutes have
    > passed.
    > I tried adding GMT+1 like so: $start = strtotime ('today 00:00
    > GMT+1'); because I suspect the fact I'm in Holland is the reason for
    > the miscalculation.
    > But this format is refused by strtotime. (-1)[/color]

    How about:

    $start = strtotime('toda y 00:00') + 3600;

    --
    If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
    Groucho, Chico, and Harpo, then Usenet is Zeppo.


    Comment

    • Daniel Tryba

      #3
      Re: StrToTime () issue

      Pjotr Wedersteers <x33159@westert erp.com> wrote:[color=blue]
      > $start = strtotime ('today 00:00');
      > $timepassed = date ('H:i', time () - $start);[/color]

      Your logic is broken, you have no idea what you are actually doing :)

      You are creating a date in 1970 plus some seconds.

      Replace 'H:i' with 'r' and you'll see the problem. Apparently the offset
      to UTC was +1 at that time, now its' +2 (DST rulez).

      You should just take the 2 timestamps, subtract and calulate whatever
      you want from the seconds, but even that goes wrong when timestamps are
      in differente DST settings... workaround is to use gmdate where there is
      not such thing...

      --

      Daniel Tryba

      Comment

      • Daniel Tryba

        #4
        Re: StrToTime () issue

        Daniel Tryba <news_comp.lang .php@canopus.nl > wrote:[color=blue]
        > workaround is to use gmdate where there is not such thing...[/color]
        ^^^^^^ should be: UTC as timezone.


        --

        Daniel Tryba

        Comment

        Working...