Date Calculation
-
i am using dotnet2005.i do my project in vb.net windows application.i want to add one year from selected date.the following code is Private Sub FromDateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FromDateTimePicker.ValueChanged ToDateTimePicker.Value = FromDateTimePicker.Value.AddYears(1).AddDays(-1) End Sub The above code is used to display as follow for (ex) using above code,if click date as 01/04/2008 in FromDateTimePicker means,then automatically displayed as 31/03/2009 in ToDateTimePicker.like this,if i click any date means,correctly worked.but if l click 29/02/2008 in FromDateTimePicker means,it must be automatically display as 27/02/2009 in ToDateTimePicker.But i want to display as 28/02/2009 in ToDateTimePicker.so in leap year above code is not working.how to solve this?
-
i am using dotnet2005.i do my project in vb.net windows application.i want to add one year from selected date.the following code is Private Sub FromDateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FromDateTimePicker.ValueChanged ToDateTimePicker.Value = FromDateTimePicker.Value.AddYears(1).AddDays(-1) End Sub The above code is used to display as follow for (ex) using above code,if click date as 01/04/2008 in FromDateTimePicker means,then automatically displayed as 31/03/2009 in ToDateTimePicker.like this,if i click any date means,correctly worked.but if l click 29/02/2008 in FromDateTimePicker means,it must be automatically display as 27/02/2009 in ToDateTimePicker.But i want to display as 28/02/2009 in ToDateTimePicker.so in leap year above code is not working.how to solve this?
-
i am using dotnet2005.i do my project in vb.net windows application.i want to add one year from selected date.the following code is Private Sub FromDateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FromDateTimePicker.ValueChanged ToDateTimePicker.Value = FromDateTimePicker.Value.AddYears(1).AddDays(-1) End Sub The above code is used to display as follow for (ex) using above code,if click date as 01/04/2008 in FromDateTimePicker means,then automatically displayed as 31/03/2009 in ToDateTimePicker.like this,if i click any date means,correctly worked.but if l click 29/02/2008 in FromDateTimePicker means,it must be automatically display as 27/02/2009 in ToDateTimePicker.But i want to display as 28/02/2009 in ToDateTimePicker.so in leap year above code is not working.how to solve this?
add some code conditional on DateTime.IsLeapYear :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
i am using dotnet2005.i do my project in vb.net windows application.i want to add one year from selected date.the following code is Private Sub FromDateTimePicker_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FromDateTimePicker.ValueChanged ToDateTimePicker.Value = FromDateTimePicker.Value.AddYears(1).AddDays(-1) End Sub The above code is used to display as follow for (ex) using above code,if click date as 01/04/2008 in FromDateTimePicker means,then automatically displayed as 31/03/2009 in ToDateTimePicker.like this,if i click any date means,correctly worked.but if l click 29/02/2008 in FromDateTimePicker means,it must be automatically display as 27/02/2009 in ToDateTimePicker.But i want to display as 28/02/2009 in ToDateTimePicker.so in leap year above code is not working.how to solve this?
-
Use this condition to check whether the year is leap or not
If (DateTimePicker1.Value.Year Mod 4 =0) Then Else EndIf