Solved

# find if today is a recurring day

Posted on 2015-01-19
150 Views
Hi:

Let's say on 10/10/2014 I have created a recurring task. It recurs on every 10 days.
How can I understand if today there is a recurring task?

Thank you.
0
Question by:myyis
• 3
• 2

LVL 142

Expert Comment

step 1: number of days between schedule start and today, using datediff
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff

step 2: use the modulo function to see if the remainder of the division (datediff ...) and the (10 days) divisor gives 0 or not:
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_mod
0

Author Comment

I see that it will be difficult for me to go over the steps. You make me super happy if you write the  query,
thank you very much.
0

LVL 142

Accepted Solution

Guy Hengel [angelIII / a3] earned 500 total points
let's consider this table:
``````create table test(d date);
insert into test values('2014-10-10');
insert into test values('2014-10-11');
insert into test values('2014-10-12');
insert into test values('2014-10-13');
``````

then, this query
``````select d
, datediff(now(), d)
, mod(datediff(now(), d), 10)
from test;
``````
:

returns this data:
`````` 	DATEDIFF(NOW(), D) 	MOD(DATEDIFF(NOW(), D), 10)
October, 10 2014 00:00:00+0000 	101 	1
October, 11 2014 00:00:00+0000 	100 	0
October, 12 2014 00:00:00+0000 	99 	9
October, 13 2014 00:00:00+0000 	98 	8
``````

where only 2014-10-11 has a remainder of 0, so that one, as start date, would mean that today is a recurring 10 day interval date, or for 2014-10-10, yesterday would have been such a date.
0

Author Comment

thank you
0

Author Comment

Hi Guy,
Can you have a look at this?
http://www.experts-exchange.com/Database/MySQL/Q_28599434.html#a40558061
Thank you.
0

## Featured Post

### Suggested Solutions

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Creating and Managing Databases with phpMyAdmin in cPanel.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

#### Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!