0

I have a mysql timestamp which looks like this: 2016-08-31 21:54:33 . I need to use this timestamp in PHP touch: bool touch ( string $filename [, int $time = time() [, int $atime ]] )

How can I best convert into the int value needed in touch?

Horst Walter
  • 13,293
  • 30
  • 115
  • 212

2 Answers2

1

If you want to convert string to timestamp you can use one of:

$str = '2016-08-31 21:54:33';
// Option #1:
strtotime($str);

// Option #2:
strptime($str, '%Y-%m-%d %H:%M:%S');
Dekel
  • 57,326
  • 8
  • 92
  • 123
1

In an object oriented syle:

$dateTime = new DateTime("2016-08-31 21:54:33");
echo $dateTime->getTimestamp();
Karim Mtl
  • 1,148
  • 3
  • 10
  • 33