开发者

How to create a date calculation (add a number of days since a particular date and write a DD/MM/YYYY result)

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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜