Amir
Amir

Reputation: 1979

Date convert issue

I try to convert below text to date, for more than 80 cases from 2011 to 2017-July it is working fine but from Aug it converts the year to the year 2018 and considers the number as a day. I want to check is there any way to convert format date exactly and properly? this piece of code is for data migration so if it work wrongly it is disaster situation.

Convert.ToDateTime("Sep-17")

The answer in my machine is: {9/17/2018 12:00:00 AM}

the correct answer should be: {9/1/2017 12:00:00 AM}

Upvotes: 1

Views: 92

Answers (1)

bommelding
bommelding

Reputation: 3037

 DateTime.ParseExact("Sep-17", "MMM-yy", CultureInfo.InvariantCulture);

Upvotes: 9

Related Questions