Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I save a timestamp to a mysql database?

I have a table in mysql for people’s posts. But I’d like to be able to get the time the post was made? How do I do it? Any help will be appreciated. The language I’m using is PHP and I’m using prepared statements.
Is it as simple as specifying a column in the database with the datatype TIMESTAMP? And how do I read a timestamp and convert it to a date?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  $timestamp = date("Y-m-d H:i:s");

check your table setup to confirm that the field is set to NOT NULL with a default of CURRENT_TIMESTAMP and above code will return you current date and time which will be in string format. Which you can push in to table.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading