user3759138
user3759138

Reputation: 41

How to insert the current date to database then retrieve it?

$query = mysql_query ('insert into pm timestamp values("'.strtotime("now").'")')
echo "<td>".date('d-M-Y H:i:s', $date3)."</td>

timestamp in database is INT(11)

I am able to get today date but I can't get the current time.

please help thank you !

Upvotes: 0

Views: 113

Answers (3)

Theo
Theo

Reputation: 21

You have to get the timestamp directly in your database with MySql and not with PHP. Change the type of your "timestamp" to timestamp and use the appropriate function "NOW()"

Your request would be like that : INSERT INTO table (timestamp) VALUES 'NOW()'

Upvotes: 2

Aleksandar Vasić
Aleksandar Vasić

Reputation: 593

time();

Gives you current date and time in unix format - timestamp

$query = mysql_query ('insert into pm timestamp values("'.time().'")')

and after that when you retreive field value to var $date3 just echo it like you did

echo "<td>".date('d-M-Y H:i:s', $date3)."</td>";

Upvotes: 1

Magus
Magus

Reputation: 2992

If you want timestamp, use time()

php > echo time();
1406880195

Upvotes: 1

Related Questions