Solved

date addition

Posted on 2001-07-11
3
2,657 Views
Last Modified: 2008-02-26
Hi,

I need a sample code for date addition.

E.g

{12/07/2001} + 200 = {28/01/2002}

Pls help urgently

regards
tridib
0
Comment
Question by:tridib
3 Comments
 
LVL 4

Expert Comment

by:ravi_raj123
ID: 6275926
<Script>
var g=new Date(2001,7,12)
g.setDate(g.getDate()+200)
alert(g.getDay()+'/'+g.getMonth()+'/'+g.getYear())
</script>

Good Luck...:)
0
 

Accepted Solution

by:
rongreen earned 50 total points
ID: 6277863
Works for addition or subtraction...

<SCRIPT LANGUAGE="JavaScript"><!--
  function asDays(ddmmyy,days) {
      // parse ddmmyy for day, month, year
      var dateArray = ddmmyy.split('/');
      sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);

  // add the number of days as milleseconds
        var odate = new Date(sdate.getTime() + (days * 86400000));

  // return value
      return (odate.getMonth()+1) + '/' + odate.getDate() + '/' + (odate.getYear() + 1900);
  }

 
  alert( asDays("12/7/2001",200) ); // gives 1/27/2002
  alert( asdays("12/7/2001",-200);  // gives 12/23/2000
  //--></SCRIPT>
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6806574
No response to Proposed Answer, assume Expert served the need here and am finalizing this today.  In the event Asker returns with additional needs here, please respond.
 
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending ASP to server side 8 33
Html date format 9 21
modify change color of text 9 39
How do I split a variable to newline 2 23
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question