简体   繁体   中英

Date Format in MYSQL with Timezone

I have to display below date like 27-Apr-2015 in mysql Monday 27 April 2015 12:12:36

How to do it.

Thanks in advance.

Regards, Abu

Try This:-

SELECT DATE_FORMAT(STR_TO_DATE('27 April 2015 12:12:36', '%d %M %Y %h:%i:%S'), "%d-%b-%Y");

First you need to convert your string to date. then you can format the same.

if your date like Monday 27 April 2015 12:12:36 PM IST
use:

SELECT DATE_FORMAT(STR_TO_DATE('Monday 27 April 2015 12:12:36 PM', '%W %d %M %Y %h:%i:%S %p'), "%d-%b-%Y");

Hope this help !

MySQL DATE_FORMAT Function is there to rescue.

SELECT DATE_FORMAT(yourDateColumn,'%W %d %M %Y %T') `Date`
FROM yourTable;

See a DEMO on SQL Fiddle .

Try this variant

SELECT DATE_FORMAT(NOW(), "%d-%M-%Y");  

This will output

02-March-2018

Or if you want shorter month name, use %b instead %M

SELECT DATE_FORMAT(NOW(), "%d-%b-%Y");  

More information you can find here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM