Convert Date to Integer

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 361
public int DateToInt32(DateTime dtCurrent)
{
int ReturnValue;
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append(dtCurrent.Year.ToString("D4"));
sb.Append(dtCurrent.Month.ToString("D2"));
sb.Append(dtCurrent.Day.ToString("D2"));

ReturnValue = Convert.ToInt32(sb.ToString());

return ReturnValue;
}

To test:-
Response.Write(DateToInt32(DateTime.Now));  
20150831

Comments or Responses

Login to post response