Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to change the date format in mysql SELECT?

Tags:

mysql

Can any one please let me know, i need to change the data format 2010-05-14 17:53 to 14/05/2010 17:53 using mysql select query

like image 511
Chakrapani Avatar asked May 19 '10 07:05

Chakrapani


People also ask

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

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. Instead, you follow the standard date format and use the DATE_FORMAT function to format the date the way you want.

Can we change the date format in MySQL?

Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().

How do I format a date in 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. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format.


4 Answers

try this select..

SELECT DATE_FORMAT(datefield, "%d/%m/%Y %H:%i") FROM <TableName> WHERE <clause>
like image 90
Prabhu M Avatar answered Oct 01 '22 15:10

Prabhu M


select date_format(date_column, "%d/%m/%Y %H:%i") from table_name
like image 22
Salil Avatar answered Oct 01 '22 15:10

Salil


Maybe this link might help you MySQL Manuel

This should do the trick :

Select DATE_FORMAT(now(),'%d/%m/%Y %H:%i');

For hour, u can use %H or %h, depending if you want 24h or 12h display. %H will set 24h, %h will set 12h.

like image 29
Terry Avatar answered Oct 01 '22 14:10

Terry


Use DATE_FORMAT to format your DATE. To solve your conversion, use the following code as a pointer

SELECT DATE_FORMAT('2010-05-14 17:53', '%d/%m/%Y %H:%i');
like image 25
Snehal Avatar answered Oct 01 '22 13:10

Snehal