I am unable to insert HTML5 default date format(mm/dd/yyyy) in mysql(YYYY-mm-dd).Please help is there any way to insert the html5 date into mysql. Or is it possible to change the html5/mysql date format?
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$password=$_POST['password'];
$gender=$_POST['gender'];
$bday=$_POST['bday'];
include('connect.php');
$y=mysql_query("insert into users values('$name','$email','$password','$gender','$bday')");
?>
MySQL retrieves and displays DATE values in ' YYYY-MM-DD ' format. The supported range is '1000-01-01' to '9999-12-31' . The DATETIME type is used for values that contain both date and time parts.
MySQL uses yyyy-mm-dd format for storing a date value. This format is fixed and it is not possible to change it. For example, you may prefer to use mm-dd-yyyy format but you can't.
In a MySQL database, the DATE_FORMAT() function allows you to display date and time data in a changed format. This function takes two arguments. The first is the date/datetime to be reformatted; this can be a date/time/datetime/timestamp column or an expression returning a value in one of these data types.
dd/mm/yyyy.
<?php
$date = date('Y-m-d',strtotime($date));
?>
To change MySQL date format in your query you can use:
...since we can see your code
EDIT:
mysql_query("insert into users values('$name','$email','$password','$gender',".date('Ymd',$bday))
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With