?
Solved

MYSQL - date format change yyyy-mm

Posted on 2014-04-04
3
Medium Priority
?
676 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
[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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 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 35

Expert Comment

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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 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