tags:

views:

32

answers:

2

I want to TRIM(LEADING 0 FROM month) FROM table1

where table1 has column month with data formatted like so: 01, 02, 03

I would like to update the data so it is formatted as: 1, 2, 3, ...

Thanks!

+4  A: 

Simplest way might be to just cast it to an int:

SELECT CAST(month as int) from table
Abe Miessler
This is the solution I ended up using, though I did it through my PHP script. But what I am really trying to get at is how to update all the existing entries in my database that are formatted with a leading zero.
DrGlass
+1  A: 

From the MySQL docs:

mysql> SELECT MONTH('2008-02-03');
-> 2

So, if you only have the month (and not the rest of the date), you could use:

SELECT MONTH(CONCAT('2010-', month, '-', '01')) FROM table1;

Source: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month

Ash White