Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date Range in days....C#

I have a query that is calling an Oracle DB from C#. I want to write the query to get data that is, at most, 5 years old.

I currently have a hard coded value for public const int FIVE_YEARS_IN_DAYS = 1825;

But, this isn't correct because of leap years. Is there a function that will give me the correct number of days in the preceeding 5 years?

like image 391
MikeTWebb Avatar asked Dec 29 '22 03:12

MikeTWebb


1 Answers

I think you want this:

DateTime now = DateTime.Now;    
now.AddYears(-5).Subtract( now ).Days
like image 160
Babak Naffas Avatar answered Jan 14 '23 00:01

Babak Naffas