Reputation: 61
I have some date issue in my php code. My code is like:
$add_remind ="15/03/2013";
$add_time = "03:00";
$add_remind_on =$add_remind." ".$add_time.":00";
$formated_add_remind_on = date('Y-m-d',strtotime($add_remind_on));
But if I print the $formated_add_remind_on
, it's printing 1970-01-01 05:30:00
.
Could you please let me know where is the error?
Thanks in advance.
Upvotes: 0
Views: 69
Reputation: 20753
Your date format doesn't seem to be supported, the only date format that is supported and looks like "xx/xx/xxxx" is the American dates but they use the first segment for the month and 15 is not a valid month.
You might need to convert your input, or use something like DateTime::createFromFormat or strptime where you can specify the format your input is in (DateTime objects come with other goodies like non global timezone support too).
Your format seems to be like this (you might want to change UTC to the timezone your timestamp created):
$d = DateTime::createFromFormat("d/m/Y H:i:s", "15/03/2013 03:00:00", new DateTimeZone('UTC'));
Upvotes: 1
Reputation: 9105
strtotime only accepts english date formats, your date should be MM/DD/YYYY to make this work.
Upvotes: 0
Reputation: 899
$add_remind ="2013-03-15";
$add_time = "03:00";
$add_remind_on =$add_remind." ".$add_time.":00";
$formated_add_remind_on = date('Y-m-d',strtotime($add_remind_on));
strtotime not accetp this format :15/03/2013
Upvotes: 2