Convert DateTime to yyyyMMdd int

What is the fastest way to convert DateTime to an int representation of yyyyMMdd format.

i.e. 01-Jan-2007 β†’ 20070101 (as in int)?

+4
source share
2 answers
int x = date.Year * 10000 + date.Month * 100 + date.Day 
+21
source
 int result = int.Parse(myDate.ToString("yyyyMMdd")); 
+10
source

Source: https://habr.com/ru/post/1300239/


All Articles