check date format from csv file insertion to DB

I am using PHP. I allow users to upload records using a csv file, which is directly inserted into MySql DB after checking the field contents to be non-empty, integer etc.
Is there a way to check if the date is in the correct format in the csv file before insertions? i used is_date() function but it doesn't seem to exist. i want to check the following:
1.  if date field is in mm-dd-yyyy or mm/dd/yyyy (notice the separator), i want to change it to MySql format ie yyyy-mm-dd before inserting
2.   if date field is in yyyy-mm-dd, then it should proceed with insertion.
MUST check that field is in MySql format & if not then if possible then change it to that before insertion. I need it all to be done using PHP. Can someone please help. Thanks in advance
Who is Participating?
try strtotime() and date() functions

try inserting something like date('Y-m-d', strtotime($theVarFromCSV));

strtotime converts basically any string to an int (the number of seconds since 1/1/1970 at midnight)
date formats an integer into whatever format you choose
ARC_UMAuthor Commented:
I didn't had a chance to see your suggestion since i was away. will try & let you know how it goes. Thanks
ARC_UMAuthor Commented:
will date('Y-m-d', strtotime($theVarFromCSV)) check fields in the form dd-mm-yyyy or dd/mm/yyyy or yyyy-mm-dd or yyyy/mm/dd & convert it to yyyy-mm-dd in MySql format for insertion in DB?
Will the date function also make sure that dd is between 1-31, mm is within 1-12 & so on?
yes exactly this
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.