Jump to content

Date Query


jbalanski

Recommended Posts

Hi

I have a table with 12 "expiry date: columns for different tickets. How can I do a query that would select all the expiry date columns that would include all dates less than today and also include 90 days in the future. I can't use multiple ANDS or OR's any suggestions?

The following is my query as it goes through the query as I add and statements there is no data. The first statement after where brings back 50 rows if I add the second it then drops to 10 and so on.........hopefully this makes sense.

SELECT
users.lname,
users.fname,
users.positionappfor,
users.hdsaliveexp,
users.firstaidexp,
users.fallproexp,
users.whimisexo,
users.regrescueexp,
users.pitsexp,
users.defdriveexp,
users.otherexp,
users.bopexp,
users.boilerexp,
users.confinedexp,
users.loaderforkliftexp,
users.jpickerboomerexp,
users.boplineexp,
users.tdgexp,
users.detflameexp,
users.driveexpire,
users.driversabstract,
users.drivedemerit
FROM
users
WHERE
(users.hdsaliveexp < date_sub(now(), interval -90 day)) AND
(users.firstaidexp < date_sub(now(), interval -90 day)) AND
(users.fallproexp < date_sub(now(), interval -90 day)) AND
(users.whimisexo < date_sub(now(), interval -90 day)) AND
(users.regrescueexp < date_sub(now(), interval -90 day)) AND
(users.pitsexp < date_sub(now(), interval -90 day)) AND
(users.defdriveexp < date_sub(now(), interval -90 day)) AND
(users.otherexp < date_sub(now(), interval -90 day)) AND
(users.bopexp < date_sub(now(), interval -90 day)) AND
(users.boilerexp < date_sub(now(), interval -90 day)) AND
(users.confinedexp < date_sub(now(), interval -90 day)) AND
(users.loaderforkliftexp < date_sub(now(), interval -90 day)) AND
(users.jpickerboomerexp < date_sub(now(), interval -90 day)) AND
(users.boplineexp < date_sub(now(), interval -90 day)) AND
(users.tdgexp < date_sub(now(), interval -90 day))
Link to comment
Share on other sites

That's an ugly looking query... you really should break these out into a separate table so that you can just have a single WHERE clause.  Otherwise, it's going to get even uglier, because you'll need ORs, and then find out which one was the match.
Link to comment
Share on other sites

I thought of doing seperate tables but I am just trying to do a report that selects all the users with the following expiry dates that are less then today or will expire within 90 days. If user one only has one expiry date he will show up if he has 2 expiry dates those dates and only those will show up if user 2 has 5 expiry dates I will see those and so on.
Link to comment
Share on other sites

Maybe I am not making myself clear. (Maybe I am complicating it)

I have a form with 16 date fields these are expiry dates for various certificates.

We can do a query that will select the appropriate data ie any dates less than today and 90 days in the future.

What ends up happening as you know is you get the user with 16 colums of dates with the one or two results from the query and the rest with dates that are over 90 days.

I created a seperate table with userid expirydate and such but then adding via the form is difficult.

Is there a way to highlight the query results in php so that if I get  the user and the 16 date colums is it possible to highlight those results ie be it bold or a different color so they are easily seen.
Link to comment
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.