I have an MSSQL database with dates 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.
views:
29answers:
2
+2
A:
// 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");
Neil Moss
2010-07-13 12:02:04
A:
try this:
private static string GetConvertedDate(int numberOfDays)
{
DateTime defaultDate = new DateTime(1970, 1, 1);
return defaultDate.AddDays(numberOfDays).ToString("dd/MM/yyyy");
}
anishmarokey
2010-07-13 12:17:07