简体   繁体   English

在MySQL中选择varchar作为日期

[英]select varchar as date in mySQL

I have a date column in the format 我有一个日期列,格式为

25 Mar 2017 07:19 pm 2017年3月25日下午7:19

I want to select date in the format dd/mm/yyyy 我想以dd / mm / yyyy格式选择日期

I have tried: cast(date as DATE), STR_TO_DATE(date, '%d/%m/%Y') but everything returns null 我已经尝试过: cast(date as DATE), STR_TO_DATE(date, '%d/%m/%Y')但是一切都返回null

any help will be appreciated. 任何帮助将不胜感激。

Use 采用

select str_to_date('25 Mar 2017 07:19 pm', '%d %M %Y')

The format specified has to match the input pattern. 指定的格式必须匹配输入模式。 As the month name is included, use %M . 由于包含了月份名称,因此请使用%M

You can parse the date using following format: 您可以使用以下格式解析日期:

SELECT STR_TO_DATE('25 Mar 2017 07:19 pm', '%d %M %Y %h:%i %p');

Here's the SQL Fiddle . 这是SQL Fiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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