Convert string to date issue

Hello all
I am trying to convert string to date.

String = 12/24/2015
Expected output =2016-02-01 ( need to add 9 days)
I am using this code = DateTime.ParseExact( str_Date,“yyyy-dd-MM”, System.Globalization.CultureInfo.InvariantCulture).AddDays(9)

Getting error :
image

@Dinesh5

str_Date = "12/24/2015"
output_Date = DateTime.ParseExact(str_Date, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture).AddDays(9).ToString("yyyy-MM-dd")

1 Like

Hi @Dinesh5

Try the below one,

- Assign -> Input = "12/24/2015"

- Assign -> Output = DateTime.ParseExact(Input.toString,"MM/dd/yyyy", System.Globalization.Cultureinfo.InvariantCulture).adddays(9).toString("yyyy-MM-dd")

Hope it helps!!

1 Like

@rlgandu So I need to give same date format as string(MM/DD/YYYY) first I need to convert it to expected format?

@Dinesh5

DateTime.ParseExact(str_Date, “MM/dd/yyyy”, System.Globalization.CultureInfo.InvariantCulture).AddDays(9).ToString(“yyyy-MM-dd”)
“MM/dd/yyyy”---- you have to pass str_Date Format
“yyyy-MM-dd”-------Your Expected Format

1 Like

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