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. C#
  4. Adding dates

Adding dates

Scheduled Pinned Locked Moved C#
questiontutorial
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.
  • K Offline
    K Offline
    kanchoette
    wrote on last edited by
    #1

    How can I add 12 years minus 1 day to a date please? So, for example, if the original date is 09/06/2009 (June 9th, 2009) the calculated date will give me 08/06/2021.

    S P D 3 Replies Last reply
    0
    • K kanchoette

      How can I add 12 years minus 1 day to a date please? So, for example, if the original date is 09/06/2009 (June 9th, 2009) the calculated date will give me 08/06/2021.

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Did you take a look at MSDN? The DateTime class contains methods for this: http://msdn.microsoft.com/en-us/library/system.datetime.addyears(VS.80).aspx[^] Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      K 1 Reply Last reply
      0
      • K kanchoette

        How can I add 12 years minus 1 day to a date please? So, for example, if the original date is 09/06/2009 (June 9th, 2009) the calculated date will give me 08/06/2021.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Something like this perhaps:

        DateTime newDate = DateTime.Now.AddYears(12).AddDays(-1);

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        1 Reply Last reply
        0
        • K kanchoette

          How can I add 12 years minus 1 day to a date please? So, for example, if the original date is 09/06/2009 (June 9th, 2009) the calculated date will give me 08/06/2021.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          public DateTime TwelveYearsMinusOne(DateTime start)
          {
          return start.AddYears(12).AddDays(-1);
          }

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
          Why are you using VB6? Do you hate yourself? (Christian Graus)

          1 Reply Last reply
          0
          • S SeMartens

            Did you take a look at MSDN? The DateTime class contains methods for this: http://msdn.microsoft.com/en-us/library/system.datetime.addyears(VS.80).aspx[^] Regards Sebastian

            It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

            K Offline
            K Offline
            kanchoette
            wrote on last edited by
            #5

            I have just realised this after I posted my question :rolleyes: Many thanks for pointing this out.

            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