Hi,

Does anyone know how to format a timestamp in mysql??

I need the time and date inserted into a db field upon registration. It does this okay - but enters it without any formatting.

I tried to make it a 'date/time' field insead of 'timestamp' but then the field was empty. I'm thinking that maybe these need to be passed as an empty field with the registration form?

All I need is for the date and time to display on a php page - so if there is some way of formatting it on the page - this would do.

Thanks to anyone who can help me!

    Not sure about MySql but for printing date() on page:

    <?php

    // stx. date(format, [timestamp])

    echo date (F jS Y, h:iA.");

    ?>

    Look up the date() Function for more info on the characters to use and what they will print. Good Luck!

      I usually use gmmktime() on registration. This stores the time as the number fo seconds since the eopch (1970 ish time). Then when I need to the time I just use the date() function that rbudj suggested.

      Go here for more info on date().

        the mySQL datetime field type typically stores the data as YYYY-MM-DD HH:MM:SS. You need to format you date like this using PHP's [man]date[/man] function or if you want to store the current time you can use the mySQL function NOW(). once stored you can pull the date out and format any way you want using PHP's date() or mySQL's DATE_FORMAT().

          Thanks for all your help 🙂

          I decided to put a hidden field in the form with the value
          <? echo date("Y-m-d H-i-s"); ?> and store this in the database as "date".

          This works well for what I need.

            Write a Reply...