Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php, date() not returning the right date/time

The code below...

$date = "02-13-2012";
$start_time = "17:30";
$end_time = "20:00";

$start_timestamp = date("m-d-Y H:i",strtotime($date." ".$start_time));
$end_timestamp = date("m-d-Y H:i",strtotime($date." ".$end_time));

print($start_timestamp);
print($end_timestamp);

Returns...

1969-12-31 19:30:00

1969-12-31 20:30:00

Does anyone have any idea why this is not working correctly?

like image 330
Brook Julias Avatar asked Jun 30 '26 09:06

Brook Julias


1 Answers

02-13-2012 17:30 is not a recognized date format. Either use day-month-year or year-month-day order, or custom parse the date format using, for example, DateTime::createFromFormat.

like image 77
deceze Avatar answered Jul 01 '26 21:07

deceze