afridy
1
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
$m=date('m');
$query="SELECT COUNT(tid) as tot
FROM transactions
WHERE MONTH(dt) < $m";
pls help me . urgent!
afridy
2
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
r937
3
why would you expect 2012/12/31 when you explicitly return 01 as the day?