Phillis
Phillis

Reputation: 155

Convert DateTime to yyyyMMdd int

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)?

Upvotes: 10

Views: 19646

Answers (2)

Joey
Joey

Reputation: 354506

int x = date.Year * 10000 + date.Month * 100 + date.Day

Upvotes: 27

Reed Copsey
Reed Copsey

Reputation: 564413

int result = int.Parse(myDate.ToString("yyyyMMdd"));

Upvotes: 15

Related Questions