Question

In my MySQL DB I've got one table storing date periods. Each period row has PSTART and PEND columns defining period start and period end dates. How to create a query which will check if one particular date is within any of these periods or not? Number of periods in not fixed!

Was it helpful?

Solution

SELECT * FROM periods WHERE [a date] BETWEEN PSTART AND PEND

OTHER TIPS

Based on your question so far, this should give you all rows where date is between PSTART and PEND - you can modify depending on your requirements for inclusivity/exclusivity:

SELECT * FROM table WHERE date>=PSTART AND date<=PEND
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top