Skip to main content
Known Participant
August 21, 2009
Answered

date function is not returning correct value

  • August 21, 2009
  • 1 reply
  • 541 views

I have used the following code to display only the value for last seven days. it works fine in homepage(www.dealfindit.com)  but in other page like category(www.dealfindit.com and click MP3 )

SELECT title, merchant, image, price, price_price, dollar_sign, click_here, listprice_text, dealexpire_text, added_text, to_shop, price_note, description, link_product, shipping_info, tax_info, other_info, deal_expire, list_price, category_items, buying_instruction, DATE_FORMAT(date_created, '%m/%d/%Y %l:%i %p') AS 'date_created_alias',DATE_FORMAT(date_created,'%W %M %d %Y') AS 'date_only'
FROM mylist
WHERE date_created > SUBDATE(NOW(), 7)
ORDER BY date_created DESC

code for category page

======================

SELECT title, merchant, image, price, price_price, dollar_sign, click_here, listprice_text, dealexpire_text, added_text, to_shop, price_note, description, link_product, shipping_info, tax_info, other_info, deal_expire, list_price, category_items, sub_category, buying_instruction, DATE_FORMAT(date_created, '%m/%d/%Y %l:%i %p') AS 'date_created_alias',DATE_FORMAT(date_created,'%W %M %d %Y') AS 'date_only'
FROM mylist
WHERE date_created > SUBDATE(NOW(), 7) AND title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%'
ORDER BY date_created DESC

This topic has been closed for replies.
Correct answer bregent

When combining AND with OR's in your where clause, be careful  of order of operations. In your case, you probably want to add parenthesis:

WHERE date_created > SUBDATE(NOW(), 7) AND (title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%')

1 reply

bregentCorrect answer
Participating Frequently
August 21, 2009

When combining AND with OR's in your where clause, be careful  of order of operations. In your case, you probably want to add parenthesis:

WHERE date_created > SUBDATE(NOW(), 7) AND (title LIKE '%colname%' OR sub_category  LIKE '%colname%' OR category_items LIKE '%colname%')