Get strtotime of a specific time in php
2 answers
If you are trying to get the time stamp today at 8pm, it is actually much easier than using it date
, since you can use relative times in strtotime
:
$curtime = strtotime('today 8pm');
If you check this with date
:
echo date('Y-m-d H:i:s', $curtime); // Returns 2014-12-17 20:00:00
Here's a complete entry on relative date formats that explains how you can plot appropriate relative dates.
+10
source to share
The best way to do it is date_create_from_format . After choosing the format options, you get something like this:
$date = date_create_from_format('d/m/Y ga', '17/12/2014 8pm');
if (!empty($date)) {//returns false if can't create date
$timestamp = $date->getTimestamp();
//echo date('d/m/Y H:i:s', $timestamp);
}
+1
source to share