php - SQL compare dates

649

I am trying to calculate if a date is between a few dates that are in my database.1

For example: I have the date:29-02-2016

I have some entries in my database that have 2 columns, astart date and aend date.

Now I want to select rows of my database that collide with the example date. All the dates are in timestamps.

So for example I have in my database the next rows:

start date: 11-2-2016 => end date: 12-2-2016  //does not match
start date: 28-2-2016 => end date: 30-2-2016  //does match

Does anyone know how to select them from my database?

508

Answer

Solution:

Do you just want to select the rows where your_date is in betweenstart_date andend_date ? A simplebetween clause would do that.

select * from your_table
where your_date between start_date and end_date

People are also looking for solutions to the problem: php - Make 5 minute interval

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.