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. adding date

adding date

Scheduled Pinned Locked Moved Visual Basic
tutorialhelpquestion
5 Posts 3 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.
  • G Offline
    G Offline
    GaryKoh
    wrote on last edited by
    #1

    hi i wish to add a value to date example 1/1/2005 add 4 days ahead so the date will be 5/1/2005 may i know how to do this by code? i try this way dim a as date a= today +4 but there is an error here state that + cannot be done by date n integer may i know how to add it to date? thank you in advance Gary

    R 1 Reply Last reply
    0
    • G GaryKoh

      hi i wish to add a value to date example 1/1/2005 add 4 days ahead so the date will be 5/1/2005 may i know how to do this by code? i try this way dim a as date a= today +4 but there is an error here state that + cannot be done by date n integer may i know how to add it to date? thank you in advance Gary

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      You can add DateTime and TimeSpan: DateTime nowPlusFourHours = DateTime.Now + new TimeSpan(4, 0, 0, 0) You can also substract one DateTime from another one and get a TimeSpan back.

      G 1 Reply Last reply
      0
      • R Robert Rohde

        You can add DateTime and TimeSpan: DateTime nowPlusFourHours = DateTime.Now + new TimeSpan(4, 0, 0, 0) You can also substract one DateTime from another one and get a TimeSpan back.

        G Offline
        G Offline
        GaryKoh
        wrote on last edited by
        #3

        hi robert i dont understand...... DateTime? i try typing it it say here DateTime is a type and cannot be used as an expression so i try this way Dim a As Date a = DateTime.Now + New TimeSpan(4, 0, 0, 0) but ending up it say operator "+" is not define for "Date" and "TimeSpan" can please explain in more detail? im using vb.net thanks Gary

        R 1 Reply Last reply
        0
        • G GaryKoh

          hi robert i dont understand...... DateTime? i try typing it it say here DateTime is a type and cannot be used as an expression so i try this way Dim a As Date a = DateTime.Now + New TimeSpan(4, 0, 0, 0) but ending up it say operator "+" is not define for "Date" and "TimeSpan" can please explain in more detail? im using vb.net thanks Gary

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          You are right, sorry. Sometimes I mix up C# and VB.Net :-D You should use: Dim a As Date a = DateTime.Now.Add(New TimeSpan(4, 0, 0, 0))

          S 1 Reply Last reply
          0
          • R Robert Rohde

            You are right, sorry. Sometimes I mix up C# and VB.Net :-D You should use: Dim a As Date a = DateTime.Now.Add(New TimeSpan(4, 0, 0, 0))

            S Offline
            S Offline
            Sebastien Lachance
            wrote on last edited by
            #5

            There is also DateTime.Now.AddDays(4) :)

            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