convert date to YYYY-MM-DD with PHP


/ Published in: PHP
Save to your folder(s)

This will convert dates from MM-DD-YYYY to YYYY-MM-DD (iso format)


Copy this code and paste it in your HTML
  1. <?
  2. function convertDate($date) {
  3. $date = preg_replace('/\D/','/',$date);
  4. return date('Y-m-d',strtotime($date));
  5. }
  6.  
  7. print convertDate('11/05/1996'); //prints 1996-11-05
  8. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.