C# Expression for adding X number of days to a date

,

I cannot find what the correct expression is for adding a specified amount of days to a given date. Sounds simple.

Epicor doesn’t seem to like the AddDays() function

It may be that the date on there is a nullable type. If that’s the case you might try:

((DateTime) ttVendorRow.Date01).AddDays(90)

Or ttVendorRow.Date01.Value.AddDays(90).

2 Likes

I think this is actually what I was thinking of. I recently learned how to deal with nullable DateTimes as well as other types and that looks very familiar.

If the value might not be set, you can test ttVendorRow.Date01.HasValue or use the GetValueOrDefault methods. But GetValueOrDefault was added in C# 6, so you can only use it in client side stuff. I think the server side is on an even older version because string interpolation doesn’t work there.

1 Like

You could try the SQL version:

dateadd(intervalunit, intervalamount, expression)

Interval unit can be the word “day” or sometimes the letter “d”. You can also use other intervals like week, month, and year. Here is an example I used in an SSRS expression:

DateAdd("d", Fields!Vendor_LateBuffer.Value, Fields!PORel_DueDate.Value)
1 Like