Hello,
I am creating an if statement to send an email to each individual within a for each loop whose Orientation Date is within the past 2 days from the day the program is ran. Any advice on how to write my condition and any variables needed?
Hello,
I am creating an if statement to send an email to each individual within a for each loop whose Orientation Date is within the past 2 days from the day the program is ran. Any advice on how to write my condition and any variables needed?
First get the date of the Orientation Date, assign to OrientationDate
Then If (Convert.ToDateTime(OrientationDate) > Date.Today.AddDays(-2))
Send email
Hi
Hope these steps would help you resolve this
In IF condition like this
CDate(yourdatevariable.ToString) >= Now.AddDays(-2)
If we know the format of date we have
Then
The expression be like this
DateTime.ParseExact(yourdatevariable.ToString,”yourdateformat”,System.Globalization.CultureInfo.InvariantCulture) >= Now.AddDays(-2)
Where yourdateformat will be like
“dd/MM/yyyy”
Or
“dd/MMM/yyyy”
Or
“dd.MM.yyyy”
Based on the date format we have in the orientation date variable
cheers @sam1313
It is having problems with the Now.AddDays part. Do i Need to set Now as some sort of variable or something
It depends on how you are trying to use it… If you are comparing two Date objects it work just fine but if you are trying to write it you’ll need to convert to a String
That would actually work
If possible can I have a screenshot of the error
Cheers @sam1313