Solved

SQL Syntax - Date Format in MySQL

Posted on 2010-08-16
5
538 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 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