Datetime TryParseExact yyMMdd parsing wrong year in linux container

Rashmi
Rashmi
Member
206 Points
38 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: 673
Total Answered: 1
Total Marked As Answer: 1
Posted On: 17-Sep-2021 20:01

Share:   fb twitter linkedin
Answers
Priya
Priya
Member
224 Points
52 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
Thanks.
 - Rashmi  15-Nov-2021 06:31
 Log In to Chat