Answer the question
In order to leave comments, you need to log in
Best practices when calculating periodic/recurring events?
What are the best practices for storing and calculating scheduled/periodic events? What database is best for storing and calculating them?
Task example: We have a training/cleaning/...etc. company. We have many clients and each client wants to have their own schedule for receiving our services. One wants biweekly on Thursdays. Another wants every 10 days. The third is every 1st day of the month...etc.
The software must calculate which customers will be served on a certain date in the future.
Which database is best for storage and calculation? Should it be computed on the database side, or is it better to sample and compute on the backend side (terrible with a large number of clients)? Should it be pre-calculated and how to do it for an indefinite period of time?
Answer the question
In order to leave comments, you need to log in
This data can not be stored at all, with the help strtotime()
you can specify relative date / time formats
// первый день этого месяца
echo gmdate('F j, Y', strtotime( 'first day of this month') ); // August 1, 2021
// последний день декабря текущего года
echo gmdate('F j, Y', strtotime( 'last day of december this year' ) ); // December 31, 2021
// понедельник на следующей неделе
echo gmdate('F j, Y', strtotime( 'Monday next week' ) ); // August 16, 2021
// следующий четверг
echo gmdate('F j, Y', strtotime( 'next Thursday' ) ); // August 19, 2021
// второй четверг этого месяца
echo gmdate('F j, Y', strtotime( 'second thursday of this month' ) ); // August 12, 2021
// +10 дней к дате
echo gmdate('F j, Y', strtotime( '10 September 2000 + 10 days') ); // September 20, 2000
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question