Trouble with converting DateTime value

Hi! I am having trouble converting a string extracted from a web page that has the following pattern “”, to a DateTime value. I have to add 30 days to that date and then insert it in the same web page with string format following the same pattern “”.
This is what I did so far but I can not get the new DateTime value into the format string to insert it again in the web page:
Get full text --> output: MyDate in string format
Assign --> NewMyDate in DateTime format = Convert.ToDateTime(DateTime.ParseExact(MyDate,“”,System.Globalization.CultureInfo.InvariantCulture).ToString(“mm.dd.yyyy”))
Assign --> NewMyDate = NewMyDate.AddMOnths(1)
Up to here everything goes fine but when I try to paste that value in the string format following “” pattern it fails:
Type Into --> NewMyDate.ToString(“”,System.Globalization.CultureInfo.InvariantCulture)

Can anyone help me please?

@FlorSiri Try below solution

DateDoc = “09.21.2019”

Datetime.ParseExact( DateDoc,“MM.dd.yyyy”,System.Globalization.CultureInfo.InvariantCulture).AddMonths(1).ToString(“MM.dd.yyyy”)

1 Like


This s fine [quote=“FlorSiri, post:1, topic:157188”]
Get full text --> output: MyDate in string format

Then while doing this
No need to convert to DateTime just this is enough
It’s MM which denotes month as mm denotes minutes
NeeMyDate = DateTime.ParseExact(MyDate,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Then this is fine as well
NewMyDate = NewMyDate.AddMonths(1)

Finally in type into be like this

Kindly try this and let know for any queries or clarification
Cheers @FlorSiri

1 Like

Perfectly worked, thank you @indra !! :slight_smile:

Thank you @Palaniyappan !! Excellent explanation, this worked perfectly well :slight_smile:

Cheers @FlorSiri

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