-3

I want to insert mm/dd/yyyy to mysql how to convert into default format and I need dynamic query for that

        $sql="INSERT INTO user_db (EMAIL,PWD,SQUE,SANS,FNM,LNM,DOB,GENDER,ROLE) values 
        ('".$email."','".$pass."','".$sq."','".$ans."','".$fname."','".$lname."','".???."','".$gen."','".$role."')";

user enter mm/dd/yyyy format convert into default format

Divyesh Kanzariya
  • 3,629
  • 3
  • 43
  • 44
  • 2
    Read this : http://stackoverflow.com/questions/2487921/convert-date-format-yyyy-mm-dd-dd-mm-yyyy – Happy Coding Sep 13 '15 at 10:32
  • STR_TO_DATE(string, '%d/%m/%Y') – splash58 Sep 13 '15 at 10:35
  • If there is no very special reason, use the standard date or datetime format and the correct field type. Otherwise you will lose a lot of functionality. When you select the fields for outputting, you can transform the date format in your select statement. – Joerg Sep 13 '15 at 10:41
  • Can you please post more details for your question so that people can answer it? – giri-sh Sep 13 '15 at 10:47

2 Answers2

0

There is no way to change what date literals MySQL accepts. They are listed in the documentation here, and are fixed. Instead, you have to change the format of the date you input. Answers to this question will tell you how.

Community
  • 1
  • 1
Anders
  • 8,307
  • 9
  • 56
  • 88
0
  • Date format in database is always yyyy-mm-dd format
  • But While fetching, you can fetch in dd-mm-yyyy format as specified below.
  • SELECT DATE_FORMAT(datecolumn,'%d-%m-%Y') AS dateColumn FROM table
Vishal
  • 26
  • 2