trouble making a date

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    #1

    trouble making a date

    Hi,

    Using PHP 4.4.4 and I'm getting an odd time stamp attempting to make a
    php date. Here's the code

    $reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
    $reqDateTS = strtotime($reqD ate);

    If $y = 2006, $m = 12, and $d = 28, I get a negative value for
    $reqDateTS. What is wrong with the above statement?

    Thanks, - Dave

  • larry@portcommodore.com

    #2
    Re: trouble making a date


    laredotornado@z ipmail.com wrote:
    Hi,
    >
    Using PHP 4.4.4 and I'm getting an odd time stamp attempting to make a
    php date. Here's the code
    >
    $reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
    $reqDateTS = strtotime($reqD ate);
    >
    If $y = 2006, $m = 12, and $d = 28, I get a negative value for
    $reqDateTS. What is wrong with the above statement?
    >
    Thanks, - Dave
    Date functions in PHP can be tricky (DST, GMT, etc. shudder),
    did you read the manual on strtotime? It probably will help you.

    Parse about any English textual datetime description into a Unix timestamp


    Comment

    • drtebi@gmail.com

      #3
      Re: trouble making a date

      The problem is very simple. You have the parameter order wrong for
      mktime. It should be this:

      $reqDate = date("Y-m-d", mktime(0, 0, 0, $m, $d, $y));


      Cheers,
      DrTebi



      On Nov 26, 7:52 pm, l...@portcommod ore.com wrote:
      laredotorn...@z ipmail.com wrote:
      Hi,
      >
      Using PHP 4.4.4 and I'm getting an odd time stamp attempting to make a
      php date. Here's the code
      >
      $reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
      $reqDateTS = strtotime($reqD ate);
      >
      If $y = 2006, $m = 12, and $d = 28, I get a negative value for
      $reqDateTS. What is wrong with the above statement?
      >
      Thanks, - DaveDate functions in PHP can be tricky (DST, GMT, etc. shudder),
      did you read the manual on strtotime? It probably will help you.
      >
      http://us3.php.net/strtotime

      Comment

      • Kimmo Laine

        #4
        Re: trouble making a date

        <drtebi@gmail.c omwrote in message
        news:1164599656 .224112.279450@ f16g2000cwb.goo glegroups.com.. .
        On Nov 26, 7:52 pm, l...@portcommod ore.com wrote:
        >laredotorn...@ zipmail.com wrote:
        Hi,
        >>
        Using PHP 4.4.4 and I'm getting an odd time stamp attempting to make a
        php date. Here's the code
        >>
        $reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
        $reqDateTS = strtotime($reqD ate);
        >
        The problem is very simple. You have the parameter order wrong for
        mktime. It should be this:
        >
        $reqDate = date("Y-m-d", mktime(0, 0, 0, $m, $d, $y));
        I don't get the double conversion... mktime already returns a unix
        timestamp, so why pass the timestamp to date and then give the date again to
        strtotime to make yet another timestamp, which is the exact same that mktime
        returned... Simplify!

        $reqDateTS = mktime(0, 0, 0, $d, $m, $y);

        Remember KISS and LOVE:
        Keep It Simple, Stupid. Leave Out Virtually Everything.

        --
        "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
        http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
        spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


        Comment

        • Curtis

          #5
          Re: trouble making a date

          Exactly! Kimmo Laine makes a good point

          However, the correct argument order for mktime is the following (from
          php.net manual):
          int mktime ( [int hour [, int minute [, int second [, int month [,
          int day [, int year [, int is_dst]]]]]]] )

          So, the mktime argument order should be:
          $timestamp = mktime(0, 0, 0, $m, $d, $y);

          Curtis

          On Nov 27, 12:21 am, "Kimmo Laine" <s...@outolempi .netwrote:
          <drt...@gmail.c omwrote in messagenews:116 4599656.224112. 279450@f16g2000 cwb.googlegroup s.com...
          >
          On Nov 26, 7:52 pm, l...@portcommod ore.com wrote:
          laredotorn...@z ipmail.com wrote:
          Hi,
          >
          Using PHP 4.4.4 and I'm getting an odd time stamp attempting to makea
          php date. Here's the code
          >
          $reqDate = date("Y-m-d", mktime(0, 0, 0, $y, $m, $d));
          $reqDateTS = strtotime($reqD ate);
          >
          The problem is very simple. You have the parameter order wrong for
          mktime. It should be this:
          >
          $reqDate = date("Y-m-d", mktime(0, 0, 0, $m, $d, $y));I don't get thedouble conversion... mktime already returns a unix
          timestamp, so why pass the timestamp to date and then give the date againto
          strtotime to make yet another timestamp, which is the exact same that mktime
          returned... Simplify!
          >
          $reqDateTS = mktime(0, 0, 0, $d, $m, $y);
          >
          Remember KISS and LOVE:
          Keep It Simple, Stupid. Leave Out Virtually Everything.
          >
          --
          "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpkhttp://outolempi.net/ahdistus/- Satunnaisesti päivittyvä nettisarjis
          s...@outolempi. net | rot13(x...@bhgb yrzcv.arg)

          Comment

          • Kimmo Laine

            #6
            Re: trouble making a date

            "Curtis" <dyer85@gmail.c omwrote in message
            news:1164624374 .849218.149770@ 14g2000cws.goog legroups.com...
            Exactly! Kimmo Laine makes a good point
            >
            However, the correct argument order for mktime is the following (from
            php.net manual):
            int mktime ( [int hour [, int minute [, int second [, int month [,
            int day [, int year [, int is_dst]]]]]]] )
            >
            So, the mktime argument order should be:
            $timestamp = mktime(0, 0, 0, $m, $d, $y);

            Whoops, I had the parameters wrong too. Thanks for corecting it, Curtis. :)

            --
            "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
            http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
            spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            Working...