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

MYSQL - date format change yyyy-mm

Posted on 2014-04-04
3
607 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

860 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