3

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?

Brook Julias
  • 2,085
  • 9
  • 29
  • 44

4 Answers4

2

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.

deceze
  • 510,633
  • 85
  • 743
  • 889
0

your date format is not correct for strtotime function

either change is to

 $date = "13-02-2012";

or to some other valid format

Jaspreet Chahal
  • 2,759
  • 1
  • 15
  • 17
0

When you format your date like xx-yy-zzz, strtotime() interprets it as a date in the normal format, not the American one, so it's dd-mm-yyyy.

entropid
  • 6,130
  • 5
  • 32
  • 45
0

See this. I think you have to change the date format.

$date = "02-13-2012";
$date = str_replace("-","/",$date);
$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);
echo "<br/>";
print($end_timestamp);
Prasad Rajapaksha
  • 6,118
  • 10
  • 36
  • 52