0

Hi there Stack Overflow community, I'm new to stack overflow so excuse me if I happen to make any mistakes etc.

Anyway, my question is that I have a time stamp on a MySQL database cell (and the column is set to a time stamp format), with a date of 2015-06-01 12:55:24 (with that format), and I wanted to convert it into an integer in my PHP code.

I've read that Strtotime() can be implemented into it to make that happen, but since I'm a newbie to PHP, I wouldn't be too sure as to how that can be done? If Strtotime() isn't the correct function / process, then what would be?

Cheers to any possible solutions, Kindest regards,

Joshua

  • 6
    see this answer: http://stackoverflow.com/questions/7029127/using-mysqls-timestamp-vs-storing-timestamps-directly. It points out that you can get the column returned as an int using MySQL's built-in function: `UNIX_TIMESTAMP()` –  Oct 25 '15 at 20:01

1 Answers1

2

Welcome to Stack Overflow.

To convert a date/time to a Unix timestamp, the strtotime() function should work just fine.

You can pass many types of date/time strings to this function, however, for your use here is an example:

$datetime = "2015-06-01 12:55:24";
$timestamp = strtotime($datetime); //1433177724

Unix Timestamp?

Simply put, the Unix Timestamp is the number of seconds since the January 1, 1970 at 00:00:00 UTC. Many web programs use this timestamp to parse dates and times.

bnahin
  • 796
  • 1
  • 7
  • 20