Datetime TryParseExact yyMMdd parsing wrong year in linux container

Rashmi
Rashmi
Member
168 Points
34 Posts

I'm trying following c# code to parse date with string format "yyMMdd".

var provider = CultureInfo.InvariantCulture;
DateTime.TryParseExact("320918", "yyMMdd", provider, DateTimeStyles.None,out var dt)

It's working fine if we are putting year 29 or less as "290918". And it's parsing as "18th Sep 2029".

But for year 30 or greater than as "320918", parsing as "18th Sep 1932".

Views: 178
Total Answered: 1
Total Marked As Answer: 0
Posted On: 17-Sep-2021 20:01

Share:   fb twitter linkedin
Answers
Priya
Priya
Member
178 Points
44 Posts
         

try to pass year in 4 digits instead of 2 digits as

var provider = CultureInfo.InvariantCulture;
DateTime.TryParseExact("20320918", "yyyyMMdd", provider, DateTimeStyles.None,out var dt)
Posted On: 21-Sep-2021 02:13
 Log In to Chat