Answer the question
In order to leave comments, you need to log in
Get the nearest day of the week?
Hello.
I store in the database, the days of the week in a row (set type) - from 1 to 7 (Mon - Sun).
Records can have at least all days selected, or some selectively.
Can you please tell me how, given the current day of the week, to choose the fastest one and get its date?
Here is an example: the record contains "1,2" - that is, Mon, Tue, today is Friday, suppose. Means I need to receive date of the next Monday.
I made a design, but it is somehow heavily loaded, maybe it can be made easier.
Answer the question
In order to leave comments, you need to log in
1. Find the position of the current day in an array of days with 7 elements (eg Wednesday - 3)
2. Find the position of the requested day (eg Monday - 1)
3. Calculate the difference (eg 7 - 3= 4)
4. Get current date + (n + 1) days (e.g. current date + (4 + 1) days)
5. Profit
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question