"yyyy" is read as 0001 instead of 2020


I was using the code below to get the correct cutoff value. It was working before but when I ran it again, the year changes from 2020 to 0001

varSample.ToString(“yyyy-MM-dd”) should return 2020-01-31 but now it returns 0001-01-31

@caduque, Where are you reading the cutoff date value from?

Can you use a write line before trying to convert it to this format, just to see if the value was extracted correct from where you are getting it.

1 Like

@caduque What Value are you passing to varSample?


Check below

Hope this helps


1 Like


It might be CultureInfo matter. Can you try the following?

.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)