更改MYSQL日期格式 [英] Change MYSQL date format

查看:121
本文介绍了更改MYSQL日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在有: mm / dd / yyyy ,我想将这些日期更改为 dd / mm / yyyy



表名称是车辆名称和列名称是:

  CRTD 
INSR
SERD
pre>

解决方案

您当前的列数据类型不是 date 您需要首先使用 STR_TO_DATE()将其转换为日期,然后转换为字符串

  SELECT DATE_FORMAT(STR_TO_DATE(colName,'%c /%d /%Y'),'%d /%c /%Y')
FROM table1



SQLFiddle Demo


I have a table in MYSQL of which 3 columns have dates and they are formatted in the not desired way.

Currently I have: mm/dd/yyyy and I want to change those dates into dd/mm/yyyy.

Table name is Vehicles and the columns names are:

CRTD
INSR
SERD

解决方案

Your current datatype for your column is not date right? you need to convert it to date first using STR_TO_DATE() and convert back to string

SELECT DATE_FORMAT(STR_TO_DATE(colName, '%c/%d/%Y'), '%d/%c/%Y')
FROM table1

SQLFiddle Demo

这篇关于更改MYSQL日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆