Jump to content

strtotime issues


cooldude832

Recommended Posts

I've got some funky results comming on strtotime function

<?php
		echo "Start date: ".date("m-d-Y", strtotime($data['date_start']))."<br />";
		echo "Start date: ".$data['date_start']."<br />";
		echo "End date: ".date("m-d-Y", strtotime($data['date_end']))."<br />";
		echo "End Date: ".$data['date_end']."<Br />";
?>

$data is the raw input in the form mm-dd-yyyy

and this is what it returns

 

Start date: 07-11-2025 (Strtotime value)

Start date: 20-02-1988  (Input)

 

End date: 07-20-2025 (strtotime value)

End Date: 20-02-1997 (input)

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/84057-strtotime-issues/
Share on other sites

The strtotime() function doesn't know how to interpret the date when the format is dd-mm-yyyy, so it is getting confused. Your best bet is to convert the input date into something strtotime() understands:

<?php
$input_date = '20-02-1988';
list ($day,$mon,$yr) = explode('-',$input_date);
comp_date = $yr . '-' . $mon . '-' . $day;
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/84057-strtotime-issues/#findComment-427875
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.