Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 and MySQL date format

Tags:

html

mysql

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')");
?>
like image 374
Vinay Jain Avatar asked Apr 18 '13 20:04

Vinay Jain


People also ask

What is the date format for MySQL?

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.

How do I change MySQL date format from DD MM to YYYY?

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.

Can we change date format in MySQL?

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.

What is the format of date in HTML?

dd/mm/yyyy.


2 Answers

<?php

$date = date('Y-m-d',strtotime($date));

?>
like image 141
AbsoluteƵERØ Avatar answered Sep 29 '22 15:09

AbsoluteƵERØ


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...

like image 22
Luigi Siri Avatar answered Sep 29 '22 15:09

Luigi Siri