I have an MSSQL database with dat开发者_如何学JAVAes stored in integer type. The number is relevant to the number of days that have passed since 01/01/1970. I need an ASP.NET code that will take the integer from the database table and convert it into a date - add the number of days onto 01/01/1970 and echo the result in DD/MM/YYYY format. For example, if the number in the database was 3, the calculation script would produce 04/01/1970.
// Get value from database
int valueFromDatabase = 3;
DateTime jan1970 = new DateTime(1970, 1, 1);
DateTime finalDate = jan1970.AddDays(valueFromDatabase);
string result = finalDate.ToString("dd/MM/yyyy");
try this:
private static string GetConvertedDate(int numberOfDays)
{
DateTime defaultDate = new DateTime(1970, 1, 1);
return defaultDate.AddDays(numberOfDays).ToString("dd/MM/yyyy");
}
精彩评论