Assign Future Date

Hello,

I am looking to assign a future date - specifically I am wanting to assign the date of a Monday 2 weeks in advance. For example if today is 10/8/2018, I need to display 10/22/2018.

Thank you for the support!
Mel

Hi @melaniewatson,

You could use the following code:
DateTime today = DateTime.Today;
int daysUntilMonday = ((int)DayOfWeek.Monday - (int)today.DayOfWeek + 14);
DateTime nextMonday = today.AddDays(daysUntilMonday);

3 Likes

I had to fix the typo in the subject line :rofl:

3 Likes

Ha! The struggle is real sometimes - thanks for looking out :wink:

1 Like

If it’s any date and you just want to add 2weeks you can use system. DateTime.today.addDays(14)

2 Likes

Hi @acaciomelo - Thank you for your response, but I am struggling to get the daysUntilMonday coded. Are you able to send a sample workbook? I must be missing something somewhere. Thanks again!

@acaciomelo The error message I am getting is saying: ‘)’ is expected

Slightly modify your expression : (CInt(DayOfWeek.Monday) - CInt(today.DayOfWeek) +14)
And check your variable type:

2 Likes

Hi @nadim.warsi - When doing the assign activity for daysUntilMonday I am now getting an error that says the expression is not a member of ‘String.’ I have my variable type set at Int32. I even deleted it all and started from scratch, but I cant seem to figure out where I am going wrong.

Hi @melaniewatson,

Please try the following code:

Dim today As DateTime = DateTime.Today
Dim daysUntilMonday As Integer = (CInt(DayOfWeek.Monday) - CInt(today.DayOfWeek) + 14)
Dim nextMonday As DateTime = today.AddDays(daysUntilMonday)

Can you show me the other variables and their types that you have set?
Check my workflow on v18.3.0 futuredate.xaml (6.6 KB) which has the above logic

I got it! I had the today variable set as string. Thanks for your help! :hugs:

1 Like

Great! :blush: