Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting TIMESTAMP to unix time in PHP?

Currently I store the time in my database like so: 2010-05-17 19:13:37

However, I need to compare two times, and I feel it would be easier to do if it were a unix timestamp such as 1274119041. (These two times are different)

So how could I convert the timestamp to unix timestamp? Is there a simple php function for it?

like image 362
Rob Avatar asked May 17 '10 15:05

Rob


People also ask

What is Unix timestamp in PHP?

Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch.

How can I change Unix timestamp to date in PHP?

To convert a Unix timestamp to a readable date format in PHP, use the native date() function. Pass the format you wish to use as the first argument and the timestamp as the second.

How can I get Unix date in PHP?

A combination of two PHP functions, the strtotime() and the date() functions, will produce an output like the one shown in the image above. The strtotime() function converts any given date string into a Unix timestamp. It only accepts the date string as a parameter.

How can I timestamp in PHP?

The PHP strtotime() function is used to convert a human readable date string into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).


1 Answers

You're looking for strtotime()

like image 169
Mark Avatar answered Sep 21 '22 18:09

Mark