String to date - XML

Hello everyone,

My job is to take a date from XML file annotation, take a number of days from another annotation and then add these days to the previous date.

I have a problem mainly with a variable type - the XML annotation is a string, but when I try to convert the “dd/mm/yyyy” format of XML annotation to the date type - it gives me a different date. Then, how to change a number of days (string) into a double variable, which I have to put inside AddDays()?

I tried the following:

date_var=DateTime.ParseExact(date_string,“dd/mm/yyyy”,System.Globalization.CultureInfo.CurrentCulture)
date_var1=date_var.AddDays(no_of_days.ToDouble).ToShortDateString

But it doesn’t work. Could you tell me why?

Hi

Try following:
date_var=DateTime.ParseExact(date_string,“dd/MM/yyyy”,System.Globalization.CultureInfo.CurrentCulture)
date_var1=date_var.AddDays(Double.Parse(no_of_days)).ToShortDateString

BR,
Topi

Well, essentially it works - it adds days, but the date in the end is in “MM/dd/yyyy” format instead of “dd/MM/yyyy”.

I tried converting it - date_var2=date_var.ToString(“dd/MM/yyyy”,System.Globalization.CultureInfo.CurrentCulture),

but it remains the same. Do you have any idea what should I change?

Use date.ToString(“dd/MM/yyyy”)

Here is an example sample:
Main.xaml (5.7 KB)

BR,
Topi