Hello wonderful TekTip community,
I am stumped on this one, I need your help:
I have a field storing a string value of a year/month like this : 200802 in a field called 'display_month' that I need to compare to NOW()...when I run this query:
SELECT display_month,
YEAR(STR_TO_DATE(wd_orders_meta.display_month, '%Y%m')) AS display_year,
YEAR(NOW()) as now_year
FROM my_table
WHERE DATE_FORMAT(STR_TO_DATE(display_month, '%Y%m'), '%Y%m') = DATE_FORMAT(NOW(), '%Y%m')
My query runs and tells returns a record that has a display_month value of 200802 (next feb) essentially saying that 200802 = 200702. It doesn't do any other month, it just seems confused about the year. I tried using YEAR() for the comparison, but it still returns 2008 = 2007. I tried casting both values as DATE() in the comparison to no avail. I tried CAST() and convert with only errors in the comparison.
I'm stumped...anyone have any thoughts?
Thanks
Paul
"If you build it....it won't work the first time.....or the second
I am stumped on this one, I need your help:
I have a field storing a string value of a year/month like this : 200802 in a field called 'display_month' that I need to compare to NOW()...when I run this query:
SELECT display_month,
YEAR(STR_TO_DATE(wd_orders_meta.display_month, '%Y%m')) AS display_year,
YEAR(NOW()) as now_year
FROM my_table
WHERE DATE_FORMAT(STR_TO_DATE(display_month, '%Y%m'), '%Y%m') = DATE_FORMAT(NOW(), '%Y%m')
My query runs and tells returns a record that has a display_month value of 200802 (next feb) essentially saying that 200802 = 200702. It doesn't do any other month, it just seems confused about the year. I tried using YEAR() for the comparison, but it still returns 2008 = 2007. I tried casting both values as DATE() in the comparison to no avail. I tried CAST() and convert with only errors in the comparison.
I'm stumped...anyone have any thoughts?
Thanks
Paul
"If you build it....it won't work the first time.....or the second