-2

i've a device that give me file logs with date format like this: 16/11/07 (today date) but when i'm trying to convert it with date() and strtotime, doesn't work and give me 1970-01-01.

 $row2 = "16/11/07;11:49:00"; 
 $par = explode(";",$row2); 
 $date = date("Y-m-d", strtotime($par[0])); 

Do you have some ideas?

I don't want to create a script with "20" in front of that date, because is not well formed coded.

Thank you

maures
  • 131
  • 1
  • 2
  • 13

1 Answers1

1

Use DateTime object.

try{
   $date = DateTime::createFromFormat('y/m/d',$my_date);
   $req_date = $date->format('Y-m-d');
   echo "Req Date : ".$req_date;
} catch (Exception $e) {
   echo $e->getMessage();
}
Aravind Pillai
  • 739
  • 7
  • 21