Check if date is between a period

Asked

Viewed 5,453 times

1

On my table, I have two columns, DT_INICIO and DT_FIM, would be an Absence table.

Let’s assume an employee is absent from DT_INICIO From (25/03/2016) until DT_FIM (27/03/2016), I need to make an appointment on the date 26/03/2016, as I check if that date is between Start and End?

Thank you.

  • Data > DT_INICIO AND Data < DT_FIM? You can use it too BETWEEN

  • You can use ...where data between data_inicio and data_fim or ...where data >= data_inicio and data <= data_fim, plain as that.

1 answer

4


You can use the between it specifies a range to be tested.

Syntax:

test_expression [ NOT ] BETWEEN begin_expression AND end_expression

Arguments?

test_expression

Is the expression to be tested in the range defined by begin_expressione end_expression. test_expression must have the same data type that begin_expression and end_expression.

NOT

Specifies that the predicate result must be denied.

begin_expression

Is any valid expression. begin_expression must have the same type of data that test_expression and end_expression.

end_expression

Is any valid expression. end_expression must have the same type of data that test_expressione begin_expression.

AND

Acts as a placeholder indicating that test_expression must be within the range specified by begin_expression and end_expression.

In short.

Select * from sua tabela
where suadata BETWEEN DT_INICIO and DT_FIM
  • Perfect! It worked perfectly! Thank you very much

Browser other questions tagged

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