Tutorial :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 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.


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »