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,663
  • 32
  • 126
  • 228

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
  • 60,707
  • 10
  • 101
  • 129
1

In an object oriented syle:

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