Jump to content

Recommended Posts

Hey all...

I'm trying to pull a date query where an inspection date is compared to the current date and all items due for inspection are displayed. If the inspection date is Dec. 21, then the notification date should be Jan. 22 (there's no consistent day count which makes this harder).

 

Here's the AND statements I have so far, but they don't work right. This is in mySQL 4.

AND ((TO_DAYS(CURDATE())-(TO_DAYS(ps.PAD_Sites_Last_Inspected))) > cci.Corp_Customer_Info_CheckAED_Interval) " .
                        "AND DATE_FORMAT(CURDATE(), '%m') > MONTH(ps.PAD_Sites_Last_Inspected) " .
                        "AND CURDATE() > (INTERVAL 1 MONTH + ps.PAD_Sites_Last_Inspected) " .
                        "AND CURDATE() > ps.PAD_Sites_Last_Inspected " .
                        "ORDER BY mCust.Members_ID ASC, mPSC.Members_ID ASC, ps.PAD_Sites_Name ASC";

 

Is there an easy way to do this right?

Link to comment
https://forums.phpfreaks.com/topic/88996-mysql-date-query/
Share on other sites

What is the connection between inspection date and norification date?

What is cci.Corp_Customer_Info_CheckAED_Interval

 

if curdate() is > last_inspected + 1 month, then it's certainly > last_inspected - so why both conditions?

 

Link to comment
https://forums.phpfreaks.com/topic/88996-mysql-date-query/#findComment-457120
Share on other sites

What is cci.Corp_Customer_Info_CheckAED_Interval

The interval is the number of days between tests. Some tests have to take place a shorter intervals than others.

 

if curdate() is > last_inspected + 1 month, then it's certainly > last_inspected - so why both conditions?

This should be >=... it's there because it need to be at least 1 month later.

 

What I'm trying to do is a query that will show all 'sites' in my database that are due for inspection. The date that a site is 'due' is the day of the following month of inspection + 1 day. For example: last inspected Jan. 21, it should be due on Feb. 22.

 

 

Link to comment
https://forums.phpfreaks.com/topic/88996-mysql-date-query/#findComment-457172
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.