Hi All,
Code for getting Date from string
string loopListValue = "19900131000000";
DateTime GetDate= Number2Date(Convert.ToInt64(loopListValue));
private DateTime Number2Date(long number)
{
string strNum = number.ToString();
int day, month, year;
DateTime validDate = DateTime.Now;
if (strNum.Length == 7)
{
strNum = "0" + strNum;
}
year = Convert.ToInt32(strNum.Substring(0, 4));
month = Convert.ToInt32(strNum.Substring(4, 2));
day = Convert.ToInt32(strNum.Substring(6, 2));
validDate = new DateTime(year, month, day);
return validDate;
}
Code for getting Date from string
string loopListValue = "19900131000000";
DateTime GetDate= Number2Date(Convert.ToInt64(loopListValue));
private DateTime Number2Date(long number)
{
string strNum = number.ToString();
int day, month, year;
DateTime validDate = DateTime.Now;
if (strNum.Length == 7)
{
strNum = "0" + strNum;
}
year = Convert.ToInt32(strNum.Substring(0, 4));
month = Convert.ToInt32(strNum.Substring(4, 2));
day = Convert.ToInt32(strNum.Substring(6, 2));
validDate = new DateTime(year, month, day);
return validDate;
}
No comments:
Post a Comment