Timestamp problem

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

    Timestamp problem

    I use PHP 4.4.0 and MySQL 4.0.26 and Mozilla Firefox.

    This code:

    $dummy = strtotime("-13 hour");
    $csql = "update citc_weather
    set imagepath = '$p_image',
    text = '$p_text',
    lastupdated = $dummy
    where id = 1";

    where lastupdated is of timestamp(14), doesn't work.

    All that gets posted in lastupdated is 00000000000000.

  • anderan@mail.ru

    #2
    Re: Timestamp problem

    Try to use

    $dummy = strtotime("-13 hour");
    $csql = "update citc_weather
    set imagepath = '$p_image',
    text = '$p_text',
    lastupdated = FROM_UNIXTIME($ dummy)
    where id = 1";

    Comment

    • anderan@mail.ru

      #3
      Re: Timestamp problem

      Try to use

      $dummy = strtotime("-13 hour");
      $csql = "update citc_weather
      set imagepath = '$p_image',
      text = '$p_text',
      lastupdated = FROM_UNIXTIME($ dummy)
      where id = 1";

      Comment

      • Hardeek

        #4
        Re: Timestamp problem

        plz check the datatype of lastupdated column in your mysql database
        table 'citc_weather'. If it was set to 'timestamp' type, it will never
        let you modify it explicitly, so if you want to change it
        programmaticall y you need to change its type to datetime.

        I 've also come across this kinda error once when whatever I was trying
        to insert or updating timestamp type column, I got 0000000000 as a
        result

        Hope it helps

        Thanks

        Regards
        IndianTroy

        Comment

        • damezumari

          #5
          Re: Timestamp problem

          Thanks! It worked!

          Here is the follow-up problem:

          I now have 20051004093359, say, in the lastupdated field which is
          timestamp(14).

          However,

          <?php
          require 'citc_connect.p hp';
          $csql = 'select
          imagepath,
          text,
          lastupdated
          from citc_weather';
          $result = mysql_query($cs ql);
          $nrows = mysql_affected_ rows();
          if ($nrows == -1) {echo 'Unexpected error in the query:<br/>';
          die($csql);};
          $row = mysql_fetch_arr ay($result);
          ?>

          <html>
          <body>
          <p>Last updated: <?php echo $row['lastupdated']; ?> </p>
          <p>Last updated: <?php echo date('l j-M h:i A', $row['lastupdated']);
          ?> </p>
          </body>
          </html>

          Gives:

          Last updated: 20051004093359
          Last updated: Tuesday 19-Jan 11:14 AM

          The last line should read:

          Last updated: Tuesday 4-Oct 9:33 AM

          What am I doing wrong?

          Comment

          • damezumari

            #6
            Re: Timestamp problem

            I found what was missing.

            This works:

            $csql = 'select
            imagepath,
            text,
            lastupdated,
            UNIX_TIMESTAMP( lastupdated) as lupdated
            from citc_weather';

            I tested the insert and select code with the 'lastupdated' field as
            data type timestamp and as datetime. It worked in both cases.

            Thanks for the help!

            Comment

            Working...