Solved

MYSQL - date format change yyyy-mm

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

810 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