Add time to current time and add date if necessery

Hi All,

I need to add 2 hours to the time below and incase if the time is 22:00 or more to add one more day to the date.
01.07.2019 17:44
The above is a string variable.
Any one know how to do this? Many thanks

1 Like

Fine if the input is
Str_date = β€œ01.07.2019 17:44”

str_date_output = If(Convert.ToInt32(Split(Str_date,” β€œ)(1).ToString.SubString(0,2))>=22, DateTime.ParseExact(Str_date,”dd.MM.yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture).AddHours(2).ToString(β€œdd.MM.yyyy HH:mm”),str_date)

Cheers @tra_my_Tran

Convert your string value to datetime value first:
datetimevar = DateTime.ParseExact(β€œ01.07.2019 17:44”,β€œdd.MM.yyyy”,CultureInfo.InvariantCulture)

Next use methods of datetime class to achieve the desired.

See DateTime Struct (System) | Microsoft Learn for more


Hi @Palaniyappan,
I tried but it s not working, can you give me a demo?
Thank you so much :slight_smile:

1 Like

here you go with a xaml
hope its resolved (9.5 KB)

Cheers @tra_my_Tran

Hi @Palaniyappan,
Thanks for your support, just tried your demo :slight_smile:
however i wanted is like:
if the text is β€œ11.09.2017 13:20” then i want result is β€œ11.09.2017 15:20”
If the text is β€œ11.09.2017 23:00” then i want the result is β€œ12.09.2017 1:00”
Is it possible to fix like that?
Thank you so much :smiley:

hi @tra_my_Tran,

lets take,
strdate1 = β€œ11.09.2017 23:00”

  1. Then, take 1 assign
    date1(DateTime) = DateTime.ParseExact(strdate1,β€œdd.MM.yyyy HH:mm”,System.Globalization.CultureInfo.InvariantCulture).AddHours(2)

  2. writeline β€”> date1.ToString(β€œdd.MM.yyyy HH:mm”)

Don’t worry about the date, it’ll change automatically, because here we’re converting that string into DateTime format and adds 2 hours in that date using datetime method called AddHours, So after adding 2 hours date will automatically change.


Hi @samir,

Thanks a lot, it s working for me ^^

Hi @tra_my_Tran,

Try the below code
Create varaible dateVar as datetime
Assign following code using assign activity
dateVar = DateTime.ParseExact(β€œ11.09.2017 13:20”, β€œdd.MM.yyyy HH:mm”,null);

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.