3

Pretty much what the title says

I basically want to do a simple query...

SELECT *
FROM sign_in_out
WHERE user_id = 6
  AND time_signed < DATE('2014-10-23 16:11:54')
ORDER BY time_signed DESC LIMIT 1

...to get the nearest signing in/out activity prior to the given day, to determine whether the user in question was signed in or out when the day started. The query above works fine but the problem is I don't have the date like that, I have the YEAR, the WEEK, and the WEEKDAY.

How do I create a DATE from these in MySQL?

Thanks

1 Answer 1

2
SELECT *
FROM sign_in_out
WHERE user_id = 6
  AND time_signed < MAKEDATE(year_col,(week_col*7+(weekday-1)))
ORDER BY time_signed DESC LIMIT 1

Check Manual MAKEDATE

1
  • Thanks for the answer. One thing though, I had to use +weekday-1 to get the expected result like so MAKEDATE({YEAR}, ({WEEK} * 7 + {WEEKDAY} - 1))
    – user1358298
    Oct 24, 2014 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.