954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Retrieve data based on date

I am attempting to retrieve records 7 days before the termination date. The code below doesn't seem to work.

CREATE VIEW vwRenewSubscription
AS
  SELECT c1.id as userId, p1.id subscriptionId,
  a1.id as advertisementPlanId,
  c1.companyName, c1.rocNo,
  a1.description, a1.fees,a1.duration
  FROM subscription AS p1, subscription AS p2, corporate AS c1, advertisementplan AS a1
  WHERE p1.id = p2.subscription_id_fk AND p1.id = p2.subscription_id_fk
  AND p1.user_id_fk = c1.id
  AND a1.id = p1.advertisementPlan_id_fk
  AND date_format(now(), '%Y-%m-%d') < p1.terminationDate
  AND date_format(now(), '%Y-%m-%d') > date_format(date_sub(p1.terminationDate, interval 7   day), '%Y-%m-%d');

Your help is kindly appreciated.

Thank You.

solomon_13000
Junior Poster in Training
88 posts since Jul 2009
Reputation Points: 24
Solved Threads: 0
 

Do not convert NOW() and terminationDate into strings for date arithmetics and comparisons.

smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: