Query to get records belongs to the previous month

Hai folks,

i have records of transactions in a table.
the date of transactions have the below format

field name : dt
data type : varchar 255
ex: 2012-11-13

now i need to get all the transactions belongs to the previous months :

i had the following and was working only until December 31st :rofl:


$m=date('m');
$query="SELECT COUNT(tid) as tot
        FROM transactions
		WHERE MONTH(dt) < $m";

pls help me . urgent!

Thank you folks ,
just found the answer


$query="SELECT COUNT(tid) as tot
        FROM transactions
		WHERE DATE_FORMAT(dt,'%Y-%m-%d') > DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";


Edited : Oops, answer seems wrong.

SELECT DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')

Returns 2012/12/01, but expected 2012/12/31 :rolleyes:

why would you expect 2012/12/31 when you explicitly return 01 as the day?