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?

2
  • touch($file, strtotime($row['time'])); - like this? Commented Sep 6, 2016 at 21:24
  • 2
    or convert the time on select SELECT UNIX_TIMESTAMP(your_time_field) ... Commented Sep 6, 2016 at 21:27

2 Answers 2

1

In an object oriented syle:

$dateTime = new DateTime("2016-08-31 21:54:33");
echo $dateTime->getTimestamp();
Sign up to request clarification or add additional context in comments.

Comments

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');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.