Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Months difference between dates [duplicate]

Tags:

.net

Possible Duplicate:
Difference in months

Hi all:

how can We calculate the months difference between two dates using LINQ ? I can find days difference using:

(p.Account.StateChangeDate.Date - DateTime.Now.Date).Days < 4

but there is no option for months.

Please suggest.

like image 881
DotnetSparrow Avatar asked Feb 28 '26 00:02

DotnetSparrow


1 Answers

Try calculating the difference in months between two dates


Pick the algorithm you want to use from that question.

Then, if you are using Linq2Sql, then almost all of those will get mapped back to the database as DATEPART type operations (I think).

Alternatively you could do the calc in SQL using a function like in http://www.sqlmag.com/article/sql-server/calculating-month-difference.aspx - and could then expose that to Linq2Sql as a function

like image 56
Stuart Avatar answered Mar 01 '26 17:03

Stuart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!