Solved

MYSQL - date format change yyyy-mm

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Access Query 4 35
Best database setup for image uploads 6 41
mysql Encryption with PHP 8 51
SQL Help joining two tables 7 34
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

14 Experts available now in Live!

Get 1:1 Help Now