Tuesday, November 17, 2015

PHP / MySQL - Converting a Date to MySql Formatted Date

function dateconvert($date,$func) {
    if ($func == 1){ //insert conversion
      list($day, $month, $year) = split('[/.-]', $date); 
      $date = "$year-$month-$day"; 
      return $date;
    }
    if ($func == 2){ //output conversion
      list($year, $month, $day) = split('[-.]', $date); 
      $date = "$day/$month/$year"; 
      return $date;
    }
}
Credit : https://chrismckee.co.uk/converting-a-date-to-mysql-formatted-date/

No comments:

Post a Comment