Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert DateTime to yyyyMMdd int

Tags:

c#

datetime

What is the quickest way to convert a DateTime to a int representation of the format yyyyMMdd.

i.e. 01-Jan-2007 --> 20070101 (as in int)?

like image 216
Phillis Avatar asked Feb 03 '10 22:02

Phillis


2 Answers

int result = int.Parse(myDate.ToString("yyyyMMdd"));
like image 163
Reed Copsey Avatar answered Oct 20 '22 00:10

Reed Copsey


int x = date.Year * 10000 + date.Month * 100 + date.Day
like image 20
Joey Avatar answered Oct 19 '22 23:10

Joey