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. Web Development
  3. JavaScript
  4. How to add Days in variable Date

How to add Days in variable Date

Scheduled Pinned Locked Moved JavaScript
tutorial
2 Posts 2 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.
  • R Offline
    R Offline
    Robymon
    wrote on last edited by
    #1

    my date is 29/02/2012 and i want to add 1 day to this date the answer should be 01/03/2012. how it is possible.I tried the following way, but not working. var Dte="29/02/2012" var today=new Date(Dte.substring(6,10),Dte.substring(3,5),Dte.substring(0,2)); today.setDate(today.getDate()+1);

    P 1 Reply Last reply
    0
    • R Robymon

      my date is 29/02/2012 and i want to add 1 day to this date the answer should be 01/03/2012. how it is possible.I tried the following way, but not working. var Dte="29/02/2012" var today=new Date(Dte.substring(6,10),Dte.substring(3,5),Dte.substring(0,2)); today.setDate(today.getDate()+1);

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

      As you are trying to create the date from a specific string, you should realise that the problem is actually at the point that you parse the date. Basically the to indexes in your substrings are out by one. Try:

      var today = new Date(Dte.substring(6,9), Dte.substring(3,4), Dte.substring(0,1));

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      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