Advanced SQL query with dates

Asked

Viewed 81 times

0

I have been in trouble for days. I have my chart and need to count how many grades are late, so that’s okay. I just don’t know how to make that appointment. I need to check if they are late, to be late she has to be with a difference of 3 days from the current date and within these 3 days I need to ignore Saturdays and Sundays , someone knows how I can do it ? . Thank you!

Structure of my table!

codigo (int), NomeCLiente Varchar , Data_operacao (TIMESTAMP)
  • http://stackoverflow.com/questions/9757919/count-days-between-two-dates-excluding-weekends-mysql-only

  • 1

    Supplement your question with the research you have already tried. Even if they do not present the final result (obviously), they will show the effort and their line of reasoning.

1 answer

1


SELECT * 
FROM minha_tabela
WHERE (
    DATEDIF(CURDATE(),Data_operacao) <=5 AND 
    WEEKDAY(Data_operacao)=5
) OR (
    DATEDIF(CURDATE(),Data_operacao) <=4 AND
    WEEKDAY(Data_operacao)=6
) OR (
    DATEDIF(CURDATE(),Data_operacao) <=3  AND 
    WEEKDAY(Data_operacao)<5)
)

Remembering that the function WEEKDAY returns:

  • 0: Second
  • 1: Tuesday
  • ..
  • 5: Saturday
  • 6: Domingo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.