Jump to content

Recommended Posts

Hi..

 

I got a problem in my SELECT Statement:

 

SELECT DISTINCT IF(ISNULL(a.LOGIN), 'rdc', '') AS LOGIN_CLASS, IF(ISNULL(a.LOGOUT), 'rdc', '') AS LOGOUT_CLASS, a.EMP_NO, a.LOGIN, a.LOGOUT, CONCAT(LNAME, ',' , FNAME, ' ', MI, '.') AS FULLNAME
FROM attendance.employee_attendance AS a JOIN hris.employment em ON (a.EMP_NO = em.EMP_NO AND em.STATUS = 'Reg Operatives') JOIN hris.personal AS p ON p.EMP_ID = em.EMP_ID
WHERE a.LOGIN BETWEEN '2012-01-16' AND '2012-02-01' OR a.LOGOUT BETWEEN '2012-01-16' AND '2012-02-01' 
OR ISNULL(a.LOGIN) OR ISNULL(a.LOGOUT) ORDER BY FULLNAME, a.LOGIN

 

I attach the 2 image, first the sample attendance which I get the data base on my select query, and the sample get attendance which is the output.

 

I notice that in the output from my query, the attendance with  2012-02-01 that has no logout did not displayed and also the NO LOGIN and  LOGOUT .

 

when i tried to select from 2012-01-16 t0 2012-02-02, the date 2012-02-01 was displayed., but I need to range it in 2012-01-16 to 2012-02-01 only.

 

Thank you

 

Thank you..

post-101569-13482403312123_thumb.jpg

post-101569-1348240331246_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/258723-problem-in-select-with-date-range/
Share on other sites

Hi

 

Think the problem is that your columns are date time fields and you are comparing them with dates. MySQL is taking 2012-02-01 and interpreting that as 2012-02-01 00:00:00. Which means 2012-02-01 05:25:00 is outside that range.

 

Would still expect it to be pickup up by the check for NULL though.

 

All the best

 

Keith

I tried to range 2012-01-16 00:00:00 to 2012-02-01 23:59:59 and it display the 2012-02-01 attendance,

 

but is there any solution to display the 2012-02-01 but no need to input 00:00:00 and 23:59:59 after the date?

 

cause I think its hazard to input a long data and also I use calendar to choose date.

 

Thank you

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.