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 Javascript Date Object

How to Add Days in Javascript Date Object

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

    I want to Add Number of Days with the Date object and get the New Date. i used this method to add Days FromDate.setDate(FromDate.getDate() +12) But this method is not working, if the month is February EG: if the From Date is 20-02-2013, if i add 12 Days with this date, will get result as 01-03-2013. Is there any other method to add days and check its leap year or not

    Richard DeemingR D N 3 Replies Last reply
    0
    • R Robymon

      I want to Add Number of Days with the Date object and get the New Date. i used this method to add Days FromDate.setDate(FromDate.getDate() +12) But this method is not working, if the month is February EG: if the From Date is 20-02-2013, if i add 12 Days with this date, will get result as 01-03-2013. Is there any other method to add days and check its leap year or not

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Are you sure you're looking at the correct month? In JavaScript, the Date object uses a zero-based month, so if getMonth returns 2, the date is in March.

      var date = new Date(2012, 01, 20);
      date.setDate(date.getDate() + 12);
      alert(date); // Displays: "Sat Mar 03 2012 00:00:00 GMT+0000 (GMT Daylight Time)"


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • R Robymon

        I want to Add Number of Days with the Date object and get the New Date. i used this method to add Days FromDate.setDate(FromDate.getDate() +12) But this method is not working, if the month is February EG: if the From Date is 20-02-2013, if i add 12 Days with this date, will get result as 01-03-2013. Is there any other method to add days and check its leap year or not

        D Offline
        D Offline
        Dennis E White
        wrote on last edited by
        #3

        Can you give an example of your code that isn't working?? I tried the following and it all appears to be working just fine. http://jsfiddle.net/SrVvn/[^]

        as if the facebook, twitter and message boards weren't enough - blogged

        1 Reply Last reply
        0
        • R Robymon

          I want to Add Number of Days with the Date object and get the New Date. i used this method to add Days FromDate.setDate(FromDate.getDate() +12) But this method is not working, if the month is February EG: if the From Date is 20-02-2013, if i add 12 Days with this date, will get result as 01-03-2013. Is there any other method to add days and check its leap year or not

          N Offline
          N Offline
          Niral Soni
          wrote on last edited by
          #4

          Hi Robymon, The example you have given is incorrect. Adding 12 days to 20-02-2013 will not give result as 01-03-2013, but will give 04-03-2013 The solutions given by "Richard Deeming" and "Dennis E White" are correct.

          Thanks & Regards, Niral Soni

          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