I'm working on a project in which I need to match two dates. One stored in the database and one is the current date time. I've decided to use unix timestamp for this. I'll convert these both values to unix timestamp and would then compare.
I used the below code to generate the unixtimestamp, but it gave me the following error :- A non well formed numeric value encountered
I have gone through half a dozen questions on stack overflow, but none helped my case.
$date =date("Y-m-d H:i:s A");
echo mktime($date);
What might be the solution ?
You are using the wrong function, you don't want to use mktime
but strtotime
$date =date("Y-m-d H:i:s A");
echo strtotime($date);
But the format of the date you are passing isn't currently supported by PHP. You'll have to drop A
(PM
and AM
).
To drop the AM/PM:
echo strtotime(substr($date, 0, -2));
If you want to generate the current unix time, just use mktime() with no arguments. Check out http://php.net/manual/en/function.mktime.php