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
Solved

SQL Syntax - Date Format in MySQL

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
SQL Server - Set Field Values ito Zero Based on Related Table 4 39
T-SQL Default value in Select? 5 37
table joins in qry 17 61
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…

840 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