# Calculate date

calculate the next send date. I have the survey that starts on some date and ends on some date. I need to be able to send the email every 3 days from the survey start until the survey end
LVL 19
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I think the idea would be to figure out the number of days from the start date to today and divide by 3, if no remainder send the email

where dateDiff(d,startDate,getDate()) % 3 = 0
and  endDate is not null
1
System Architect, CF programmer Author Commented:
Well the messages need to go out exactly every  3 or 4 or 5 days and etc days . OS the logic will not be correct. when.

For example, every 3 days from 1/1/2018 will be 1/4/2018, 1/7/2018, 1/10/2018 and etc up until the end data for example 2/1/2018
0
Commented:
Ok, I made the assumption that the end date would be populated when it's time to stop.

So the only change is instead of checking if the endDate is empty, check to see if the endDate has passed,  if you need to change the 3 days to a 4 or 5 days, just change the 3 in my example.   You could even set it as a field on the record..

where dateDiff(d,startDate,getDate()) % emailFrequency = 0

where startDate and emailFrequency are columns in the table and emailFrequency is a number such as 3,4, or 5...
make sure emailFrequency is a positive integer and has a value
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

System Architect, CF programmer Author Commented:
I need also use the end date so the calculation will be stopped
0
Commented:
right, just make your where clause stop when the end date is past the getDate()     where endDate < getDate()
0
System Architect, CF programmer Author Commented:
gdemaria. is this sql expression is equal to this ColdFusion expression

<cfif dateDiff('d',dateFormat(startDate,"mmm-dd-yyyy"),DateFormat(now(), "mmm-dd-yyyy")) mod locdeliveryDays eq 0>
0
Commented:
yes, but you don't need to format the dates.   DateDiff is expecting dates, formatting a date is only used for display

<cfif dateDiff('d',startDate,now()) mod locdeliveryDays eq 0>
0
System Architect, CF programmer Author Commented:
So will this statement be true

<cfif (dateDiff('d',startDate,now()) mod locdeliveryDays eq 0) and DateDiff('d',now(),locEndDate) gt 0>
0
Commented:
it will be true depending on the value of startDate and locEndDate

It does look correct
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.