i have a date '07/23/2009'
and a time '18:11'
and i want to get a timestamp out of it :
here is my example:
date_default_timezone_set('UTC');
$d = str_replace('/', ', ', '07/23/2009');
$t = str_replace(':', ', ', '18:11');
$date = $t.', 0, '.$d;
echo $date;
echo '<br>';
echo $x = mktime("$date");
the issue is that $x
gives me the current timestamp.
any ideas?
it gives error because mktime function require all values of numbers only and this function gives only date . if you try like
then it will work.
so your complete code will be
//if you want timestamp then use
Thanks
Use the DateTime class:-
or:-
IMPORTANT:
In addition to above answers ,there is an important thing that one must follow.Always use the With() function(see below) i.e
Always use :
Do not use:
REASON:(different outputs, check below)
OUTPUTS:
Try using strtotime
for your case your code should be