Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Date Calculation

Date Calculation

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sathyan_8294
    wrote on last edited by
    #1

    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?

    S L G 3 Replies Last reply
    0
    • S sathyan_8294

      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?

      S Offline
      S Offline
      sathish s
      wrote on last edited by
      #2

      Use this condition to check whether the year is leap or not If (DateTimePicker1.Value.Year Mod 4 =0) Then Else EndIf

      G 1 Reply Last reply
      0
      • S sathyan_8294

        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?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.


        1 Reply Last reply
        0
        • S sathyan_8294

          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?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Just subtract the day before you add the year: ToDateTimePicker.Value = FromDateTimePicker.Value.AddDays(-1).AddYears(1)

          Experience is the sum of all the mistakes you have done.

          1 Reply Last reply
          0
          • S sathish s

            Use this condition to check whether the year is leap or not If (DateTimePicker1.Value.Year Mod 4 =0) Then Else EndIf

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            Note: That is not the complete condition to check for leap years, it only works for years close to now.

            Experience is the sum of all the mistakes you have done.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups