Web Analytics Made Easy -
StatCounter TimeStamp - CodingForum

Announcement

Collapse
No announcement yet.

TimeStamp

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TimeStamp

    Hello

    I have got a mysql database that has automatic timestamp in the table.

    In the php page i would like to display the time stamp:

    My code
    PHP Code:
    <? echo "$date_time"?>
    How can i get it to display 2005/07/30 19:02:46 insted of 20050730190246

    Many thanks

  • #2
    PHP Code:
    $thetime = date(Y/m/d H:i:s);

    <? echo "$thetime"?>
    I think.
    markaylward.co.uk

    Comment


    • #3
      Yep, but...
      PHP Code:
      $thetime date('Y/m/d H:i:s'$date_time); 
      There, now its all good, that will format for your timestamp instead of the current time.
      PHP Code:
      header('HTTP/1.1 420 Enhance Your Calm'); 
      Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

      Comment


      • #4
        You should know that the timestams that are stored in type "timestamp" fields are not the same type of timestam as PHP uses.
        I'm not sure if this was any help, but I hope it didn't make you stupider.

        Experience is something you get just after you really need it.
        PHP Installation Guide Feedback welcome.

        Comment


        • #5
          You can easily convert the timestamp to a more readable date:
          PHP Code:
          function mySQLDate($time) {
            
          $parts str_split($time2);
            return 
          $parts[0].$parts[1].'/'.$parts[2].'/'.$parts[3].' '.$parts[4].':'.$parts[5].':'.$parts[6];
          }

          echo 
          mySQLDate($date_time); 
          dumpfi
          "Failure is not an option. It comes bundled with the software."
          ....../)/)..(\__/).(\(\................../)_/)......
          .....(-.-).(='.'=).(-.-)................(o.O)...../<)
          ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
          ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
          Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

          Comment


          • #6
            Originally posted by marek_mar
            You should know that the timestams that are stored in type "timestamp" fields are not the same type of timestam as PHP uses.

            Didn't even notice that, lol. I thought you meant a user inserted timestamp. Lol, guess I should pay more attention when reading.
            PHP Code:
            header('HTTP/1.1 420 Enhance Your Calm'); 
            Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

            Comment


            • #7
              Originally posted by Fou-Lu
              Yep, but...
              PHP Code:
              $thetime date('Y/m/d H:i:s'$date_time); 
              There, now its all good, that will format for your timestamp instead of the current time.

              It is displaying the year as 2038 when it is 2005 in the database? Any ideas?

              Comment


              • #8
                Read the two posts after that post.
                I'm not sure if this was any help, but I hope it didn't make you stupider.

                Experience is something you get just after you really need it.
                PHP Installation Guide Feedback welcome.

                Comment


                • #9
                  that function thing did not work

                  Comment


                  • #10
                    You will laugh. It works for me.
                    How are you using it?
                    PHP Code:
                    <?php
                    $date 
                    '20050730190246';
                    function 
                    mySQLDate($time) { 
                      
                    $parts str_split($time2); 
                      return 
                    $parts[0].$parts[1].'/'.$parts[2].'/'.$parts[3].' '.$parts[4].':'.$parts[5].':'.$parts[6]; 


                    echo 
                    mySQLDate($date);
                    // echos 2005/07/30 19:02:46  
                    ?>
                    I'm not sure if this was any help, but I hope it didn't make you stupider.

                    Experience is something you get just after you really need it.
                    PHP Installation Guide Feedback welcome.

                    Comment


                    • #11
                      Or perhaps a simpler solution:

                      Code:
                       $thetime = date('Y/m/d H:i:s', strtotime($date_time));
                      Whats the point of a signature?

                      Comment


                      • #12
                        strtotime() will return -1 when you try to use it with a mysql timestamp.
                        Valid date input formats: http://www.gnu.org/software/tar/manu...ter/tar_7.html
                        Last edited by marek_mar; Aug 2, 2005, 01:31 PM.
                        I'm not sure if this was any help, but I hope it didn't make you stupider.

                        Experience is something you get just after you really need it.
                        PHP Installation Guide Feedback welcome.

                        Comment


                        • #13
                          My mistake, I usually use the DateTime field in mysql. Makes for easier days with the strtotime function.
                          Whats the point of a signature?

                          Comment


                          • #14
                            Originally posted by marek_mar
                            You will laugh. It works for me.
                            How are you using it?
                            PHP Code:
                            <?php
                            $date 
                            '20050730190246';
                            function 
                            mySQLDate($time) { 
                              
                            $parts str_split($time2); 
                              return 
                            $parts[0].$parts[1].'/'.$parts[2].'/'.$parts[3].' '.$parts[4].':'.$parts[5].':'.$parts[6]; 


                            echo 
                            mySQLDate($date);
                            // echos 2005/07/30 19:02:46  
                            ?>

                            i get this:

                            Fatal error: Call to undefined function: str_split() in /home/corner/public_html/view.php on line 62

                            Comment


                            • #15
                              Ok that makes sense. You're not using PHP5 right (I do on my test server/debugger)?
                              I think it could be done in some better way but it works.
                              PHP Code:
                              <?php 
                              $date 
                              '20050730190246'
                              function 
                              mySQLDate($time)
                              {
                                  
                              $parts explode(','chunk_split($time2','));
                                  return 
                              $parts[0].$parts[1].'/'.$parts[2].'/'.$parts[3].' '.$parts[4].':'.$parts[5].':'.$parts[6];
                              }

                              echo 
                              mySQLDate($date); 
                              // echos 2005/07/30 19:02:46   
                              ?>
                              I'm not sure if this was any help, but I hope it didn't make you stupider.

                              Experience is something you get just after you really need it.
                              PHP Installation Guide Feedback welcome.

                              Comment

                              Working...
                              X