Jump to content

Problem with Date formating


slashng

Recommended Posts

Hi,

I having problem with converting the format of the date:

$_POST['date'] = "13-11-2006";

echo $_POST['date']."<br>";
echo date("Y-m-d",strtotime($_POST['date']));

OUTPUT:
13-11-2006
2019-04-29

-------------------

I want my Output to be
13-11-2006
2006-11-13

--------------------

Please advise!
Thanks!

Link to comment
https://forums.phpfreaks.com/topic/27100-problem-with-date-formating/
Share on other sites

DD-MM-YYYY is not a readable format by strtotime(). It is expecting a YYYY-MM-DD or MM/DD/YYYY format instead. So, you'll want to run a little altering to get it to be recognized:
[code]
<?php
$date = "13-11-2006";
echo $date;
list($d, $m, $y) = explode('-', $date);
echo "$y-$m-$d";
?>
[/code]

Good luck

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.