Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
How we can add no. of months in date (dd/MM/yyyy) format.
Posted
Comments
Abdul Quader Mamun 14-Aug-12 4:31am    
easy Question!
AmitGajjar 14-Aug-12 4:42am    
can you post your code? do you have this data as string ?

You can try like bellow:
XML
<asp:boundfield datafield="ModifiedDate" headertext="Modified Date" dataformatstring="{0:dd/MM/yyyy}" xmlns:asp="#unknown" />


Thanks,
 
Share this answer
 
v2
If you are using DateTime datatype, you can use AddMonths method. If you are using string to take care of dates,

1. It is not right.
2. Convert it to DateTime and then add months.
 
Share this answer
 
C#
DateTime _dt = DateTime.Now.AddMonths(no of months);
string _dateSting = _dt.ToString("dd/MM/yyyy");
 
Share this answer
 
v2
Comments
Member 8921522 14-Aug-12 6:02am    
Thank u its work
convert your string to dateTime type and than AddMonths, below is my example:

VB
dim strDate as string="16/04/1987"
dim dtDate as DateTime
       
        If DateTime.TryParseExact(strDate, "dd/MM/yyyy", Nothing,      DateTimeStyles.None, dtDate) Then
           console.write("Date Add Month::" & dtDate.AddMonth(1))
else
        console.write("invalid format")
        End If
 
Share this answer
 

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