You cannot store dates as dd-mm-yyyy in the database as the database date format is yyyy-mm-dd. Therefore you need to convert dates from dd-mm-yyyy to yyyy-mm-dd before you insert or update your db and vice versa to display the date in your required format when displaying.

Based on the way you are coding your PHP the easiest way to do this is

As @tiger has pointed out, take a look at the PHP date functions to see all the ways to format dates as you need. I am not sure if you use or understand OOP but there is actually an in-built date class with PHP which you can use to format dates as well http://php.net/manual/en/datetime.construct.php

simplypixie wrote:You cannot store dates as dd-mm-yyyy in the database as the database date format is yyyy-mm-dd. Therefore you need to convert dates from dd-mm-yyyy to yyyy-mm-dd before you insert or update your db and vice versa to display the date in your required format when displaying.

Based on the way you are coding your PHP the easiest way to do this is

As @tiger has pointed out, take a look at the PHP date functions to see all the ways to format dates as you need. I am not sure if you use or understand OOP but there is actually an in-built date class with PHP which you can use to format dates as well http://php.net/manual/en/datetime.construct.php

When i enter value as 20/05/1978 and then use the below code$emp_dob = date('Y-m-d', strtotime($_POST['emp_dob'])); it shows as 1970-01-01 . Why is it so . It should display 20/05/1978. I have DataType as Date in Database.

Sorry, it is so long since I have formatted dates this way (i.e. without using the inbuilt php datetime class) that I forgot that if you use slashes in a date that strtotime will see it as a US date format and therefore will think your format of dd/mm/yyyy is actually mm/dd/yyyy and therefore return an incrrect time string.

In order to get your dd/mm/yyyy date to be reformatted by strtotime it first needs to be changed to dd-mm-yyyy

simplypixie wrote:Sorry, it is so long since I have formatted dates this way (i.e. without using the inbuilt php datetime class) that I forgot that if you use slashes in a date that strtotime will see it as a US date format and therefore will think your format of dd/mm/yyyy is actually mm/dd/yyyy and therefore return an incrrect time string.

In order to get your dd/mm/yyyy date to be reformatted by strtotime it first needs to be changed to dd-mm-yyyy

I enter date in format 1978-04-12 . I want this value to be stored in Database. Please forget about other posts regarding this issue. I simple want that Date is entered in HTML form and it should be saved . Database field has DataType Date.