Add Date Not working

May 16, 2013 at 6:16 PM
Hi! We're using the "Add Date" functionality just adding a number to a date and it doesn't seem to work.
Is that a registered issue?
Thanks.
May 16, 2013 at 7:51 PM
There is a built-in assumption of a 6:00 end-of-business day. Is this what you're running into?
May 16, 2013 at 7:55 PM
Hi! No, it's more simple. I'm not working with business days. Just days.
Let's say, in example:

6/1/2013

i try to add 2 months. But the date remains the same.

I just noticed that it only works when i add "months" AND "days".
If i only add "months", it doesn't work.
Thanks.
May 17, 2013 at 1:39 PM
Edited May 17, 2013 at 6:48 PM
Matias,

I was able to confirm your findings. I had other problems with this custom workflow step, related to the end-of-business-day hour, as noted above, but also, because the datetime being passed to a method is universal time and it needs to be local time.

I wrote my own plug-in to do the job. This is not difficult.

Here's the original code; your problem originates in the first line:
 if (start != DateTime.MinValue && DaysToAdd.Get<int>(executionContext) != 0)
            {
                result = start.AddYears(YearsToAdd.Get<int>(executionContext))
                              .AddMonths(MonthsToAdd.Get<int>(executionContext))
                              .AddDays((7*WeeksToAdd.Get<int>(executionContext)) + 
                                       DaysToAdd.Get<int>(executionContext))
                              .AddHours(HoursToAdd.Get<int>(executionContext))
                              .AddMinutes(MinutesToAdd.Get<int>(executionContext));
            }

            Result.Set(executionContext, result);
You can see the calculation only occurs if the Days Added is not equal to 0
Coordinator
Jul 9, 2013 at 2:34 PM
mfriedenthal,

If you provide me with the correct logic (code..) for this segment, I'll be happy to update it. Perhaps we should pass in a user as one of the parameters to get their local time to properly deal with multiple timezoned users.

-Carlton
Mar 11, 2014 at 9:07 PM
I ran into the same problem with the AddDays option. It wasn't until I changed the parameters to include both months and days, the process wouldn't work. I wanted to add 5 years to a date. Putting in just 5 in the Years option didn't update the date. I had to enter in 59 months and 31 days to make it work.

You should get that fixed! I spent about an hour on this trying to figure out what I did wrong just to find that it was already a reported bug that nobody seemed to have gotten around to fix!

Thanks for that!
Mar 12, 2014 at 2:26 PM
For Carlton, Mark Purnell, and other interested parties:

This was a year ago but I made to following changes for my installation:

The original signature for method ModifyDateTime was:
public static DateTime ModifyDateTime(EntityCollection calRules, bool checkLastDayOnly, DateTime date,
                                              Operations operation, int days, int hours, int minutes)
I changed it to:
public static DateTime ModifyDateTime(EntityCollection calRules, bool checkLastDayOnly, DateTime date,
                                              Operations operation, int days, int hours, int minutes, String clienttimezone = "EST")
I added a config file setting so that I could easily change the end-of-business hour, if neccessary:
 // 05/02/2013 MIF - Start and End-of-business changed to Setting; for more control:
 //if (date.Hour > 18)
 Int32 iEndOfBusinessHour = Properties.Settings.Default.EndOfBusinessHour;
 Int32 iStartOfBusinessHour = Properties.Settings.Default.StartOfBusinessHour;
and adjust iEndOfBusinessHour appropriately:
//Since we want to be able to add hours up to but not past the value of iEndOfBusinessHour
//(for example, up to 7:59 PM), we want to subtract an hour before we adjust for Time Zone:
            switch (clienttimezone)
            {
                case "EST":
                    iEndOfBusinessHour = iEndOfBusinessHour + -1;
                    break;
                case "CST":
                    iEndOfBusinessHour = iEndOfBusinessHour + 0;
                    break;
                case "MST":
                    iEndOfBusinessHour = iEndOfBusinessHour + 1;
                    break;
                case "PST":
                    iEndOfBusinessHour = iEndOfBusinessHour + 2;
                    break;
                case "AST":
                    iEndOfBusinessHour = iEndOfBusinessHour + 3;
                    break;
                case "HST":
                    iEndOfBusinessHour = iEndOfBusinessHour + 4;
                    break;
            }
and, finally:
if (date.Hour > iEndOfBusinessHour)
            {
                adjustend = new DateTime(adjustend.Year, adjustend.Month, adjustend.Day,
                                         operation == Operations.Add ? iStartOfBusinessHour : iEndOfBusinessHour, 0, 0);
                date = FindDateXBizDays(calRules, adjustend, 1, operation);

            }

            else if (date.Hour < iStartOfBusinessHour)
            {
                adjustend = new DateTime(adjustend.Year, adjustend.Month, adjustend.Day,
                                         operation == Operations.Add ? iStartOfBusinessHour : iEndOfBusinessHour, 0, 0);
                date = adjustend;
            }

            return date.ToUniversalTime();