Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Anyone can help me to update date. I need to update the month only without changing the time

eg: 2002-09-11 13:37:14.000
Posted
Comments
OriginalGriff 13-Jul-11 6:39am    
From the date format, should we assume this is SQL Server related? Or do you need to change the Month part only for a DateTime in C#?
kkgd 13-Jul-11 6:46am    
Yes, database is SQL server 2005. I only need to change the month from 09 to 08 for some data in table

SELECT DATE_ADD('2008-12-15', INTERVAL 1 MONTH)

Output:

2009-01-15
 
Share this answer
 
Comments
kkgd 13-Jul-11 7:20am    
Thank you
DateTime dt = DateTime.Now.AddMonths(1);


Easy when you actually read the documentation. http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^]
 
Share this answer
 
How do you need to update the month? i.e., add a predefined number of months to the DateTime, change the Month element of the DateTime to a different value defined elsewhere etc?
 
Share this answer
 
Comments
kkgd 13-Jul-11 7:21am    
I need to change the month from 08 to 07.

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