Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get exact 3 months ago date and time from today's date and current time using C#

Tags:

c#

asp.net

I want to get data from database which is saved from past 3 months for that i have current date and time but how to calculate 3 months ego date and time, SO that i can pass these 2 dates in the query and get the data which was saved between these dates

like image 337
Swati Awasthi Avatar asked Nov 29 '22 16:11

Swati Awasthi


1 Answers

Use the AddMonths method:

DateTime ago = DateTime.Now.AddMonths(-3);
like image 82
Guffa Avatar answered Dec 01 '22 07:12

Guffa