C# .net Datetime to Integer value
I am really new to C# and I am having problem in converting DateTime to it's Integer date format. I have search already the net but I did not find my answer.
I want is to convert the current Date to integer. Example the date "2011-08-11" in format "yyyy-MM-d开发者_如何学God" has an integer value of 734360
myDateTime.Ticks
will give you a uniquely representative Int64
value if that is what you need.
Pervasive uses days since 1/1/1.
To convert from int to a date use
new DateTime(1, 1, 1).AddDays(734360)
To convert to an int from a date use
TimeSpan t = (new DateTime(2011, 08, 11)-new DateTime(1, 1, 1));
int days = (int)t.TotalDays+1;
You can try this too:
DateTime MyDate = new DateTime();
int Year = MyDate.Year;
int Month = MyDate.Month;
int Day = MyDate.Day;
if it is what you're looking for.
int calculation;
DateTime processDate;
calculation = Convert.ToInt32(Convert.ToString(processDate));
u can also use this way.
精彩评论