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?
Asked
Active
Viewed 1,016 times
-1
-
What exactly is the problem? If you have a field in the database for storing the timestamp, you can either populate it via MySQL's time-related functions, or you could populate the field by passing in a value from PHP based on the time the query is generated. Or you could add an extra SELECT column in your query and add in the time the query is ran. – Kevin Y Feb 07 '22 at 05:11
-
you can use timestamp in column and send data through php. more on this topics https://stackoverflow.com/a/9541074/11168176 – Saikat Roy Feb 07 '22 at 05:12
3 Answers
1
$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.

Who Do You think am i
- 410
- 1
- 4
- 13
1
When specifying a column in the database, Use datetime and as default, select current time
If you want to use this data, just extract from database and use date('y/m/d', strtotime($time));

Matheus assi
- 66
- 5
0
If the column is NOT NULL with DEFAULT CURRENT_TIMESTAMP you don't need to mention the column in the INSERT.