Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
What is the date function to subtract 6 months from current date?

Thank you..
Posted
Comments
VJ Reddy 14-May-12 23:26pm    
Thank you for accepting the solution :)
Member 12734740 27-Mar-18 5:52am    
ok

1 solution

I think the AddMonths method of DateTime structure can be used with a negative value as below
C#
DateTime today = DateTime.Now;
DateTime sixMonthsBack = today.AddMonths(-6);
Console.WriteLine (today.ToShortDateString());
Console.WriteLine (sixMonthsBack.ToShortDateString());

//Output
//5/15/2012
//11/15/2011
 
Share this answer
 
v2
Comments
member60 15-May-12 0:24am    
5!
VJ Reddy 15-May-12 0:30am    
Thank you, member60.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900