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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.