Solved

MYSQL - date format change yyyy-mm

Posted on 2014-04-04
3
559 Views
Last Modified: 2014-04-04
Hello Experts,

I have a question about mysql, which is new to me.  I have a date formatted field, example 3/1/2014.  I would like to convert this into 2014-03.  It needs to have a padding for single digit months 1-9, to show 01, 02, 03.

I have tried a few ways but nothing works right.

Thank you!


update:  I tried the following:

CONCAT(YEAR(EC.Date), '-', LPAD(MONTH(EC.Date), 2, '0')) as YEAR_MONTH and the output is
323031342d3033

I tried parsing out yr and mo, I get the same ouput:

CONCAT(yr, '-', right(concat('00',mo),2)) AS yr_mo,
0
Comment
Question by:Maliki Hassani
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39978839
Use DATE_FORMAT(ec.date, "%Y-%m")

http://www.w3schools.com/sql/func_date_format.asp

HTH,
Dan
0
 

Author Closing Comment

by:Maliki Hassani
ID: 39978857
Thank you!
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39978858
Glad I could help!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now