0

I have to create timestamp for 8 PM everyday to compare it with some timestamp in database. How can I create it?

$ts = '2015-05-12 12:00:20' is what I have stored in database.

I need this $ts_8pm = '2015-05-12 20:00:00' so that I can take some action when this meets.

2 Answers 2

2

It will be easier to create it dynamically each day:

// Date-time will have value of 'now'
$dateTime = new DateTime();
// Override current time
$dateTime->setTime(20, 0);
$timestamp = $dateTime->getTimestamp();

Parsing a string makes very little sense, as you would have to generate that string first.

Sign up to request clarification or add additional context in comments.

Comments

2

strtotime is specifically there for that purpose

strtotime — Parse about any English textual datetime description into a Unix timestamp

 $ts_8pm=strtotime('2015-05-12 20:00:00'); 

You can also use this, better, approach

$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, '2015-05-12 20:00:00');
$ts_8pm=$date->format('U');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.