Solved

SQL Syntax - Date Format in MySQL

Posted on 2010-08-16
5
539 Views
Last Modified: 2012-05-10
Hi Guys,

I have a field (varchar), and it contains like this :

Closing_Date
---------------
27/07/2005
17/12/2010

I wanna have "select syntax" that convert the date into this format : YYYY-MM-DD HH:MM:SS

So it will be like this : 2005-07-27 00:00:00, and 2010-12-17 00:00:00

I try this syntax, but it gave NULL : select str_to_date(closing_date, "%d-%b-%Y") from table1

Please help. Thanks before.
0
Comment
Question by:softbless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
ID: 33450749
Try this.  '%b' was expecting a text like 'Jan', '%m' is looking for a number.
select str_to_date(closing_date, "%d-%m-%Y") from table1;

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33450762
select cast(concat(
      right(Closing_date,4),mid(Closing_Date,4,2),left(Closing_Date,2))
      as datetime)
from tbl
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 200 total points
ID: 33450766
Or

select str_to_date(closing_date, "%d/%m/%Y") from tbl;
0
 
LVL 7

Assisted Solution

by:jhp333
jhp333 earned 150 total points
ID: 33450769
Try this:

SELECT CAST(STR_TO_DATE(closing_date, "%d/%m/%Y") AS DATETIME)
0
 

Author Closing Comment

by:softbless
ID: 33574507
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
remote mysql 8 52
MSSQL join different row from other table 14 80
SQL Server how to create a DYNAMIC TABLE? 11 50
Populating a table from inside a trigger 2 11
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question