Date format for mysql input

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

This snippet collects a date from a var and formats it into the correct format for database date entry

Copy this code and paste it in your HTML
  1. //date from a form in the format of dd/mm/yyyy
  3. $date_array = explode("/",$date); // split the array
  4. $var_day = $date_array[0];//day seqment
  5. $var_month = $date_array[1];//month segment
  6. $var_year = $date_array[2];//year segment
  7. $departure = "$var_year-$var_day-$var_month";//join them all together to input into a mysql table

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.