Solved

Increment date using javascript

Posted on 2004-10-22
5,259 Views
Last Modified: 2013-12-18
- I have a date field in Notes named RD (Requested Date).
- I have a expected transit time field called TransitTime which is simply a number of days (ie: 5)

I simply want to place some javascript that will take the number of days found in the TransitTime field and increment the RD date by that amount of days to determine the DeliveryDate.

ie:
RD is 1/31/2005
Transit Time is 5
DeliveryDate should be calculated via javascript as 2/4/2005.
0
Question by:snocross
    15 Comments
     
    LVL 46

    Expert Comment

    by:Sjef Bosman
    Basically:
        rd= new Date(y,m,d)
        dd= rd + tt*24*60*60*1000
        ddfield= dd.getMonth() + "/" + dd.getDay() + "/" + dd.getYear()

    Only works in countries with M/D/Y date format. Otherwise, you must use
        ddfield= dd.toUTCString()

    Replace ddfield with the correct sequence for your field, like
        document.forms[0].field.value
    0
     
    LVL 24

    Expert Comment

    by:HemanthaKumar
    Doesn't notes field calculation (using @Adjust) do the same job !

    ~Hemanth
    0
     
    LVL 46

    Expert Comment

    by:Sjef Bosman
    Yep, but not immediately on-screen, and I suppose that's the idea
    0
     
    LVL 24

    Expert Comment

    by:HemanthaKumar
    you can call recalc function.. sno I have mentioned that trick in one of your question I believe
    0
     
    LVL 31

    Expert Comment

    by:qwaletee
    See this iste: http://www.javascriptmall.com/jsc/jsC4Udate.htm#DateTime17
    Which has this code:
    <SCRIPT Language="JavaScript">
    <!-- hide from old browsers
    var today = new Date()
    var targetDate = new Date("12/31/1999") //use full year
    var timeAfterTarget = Math.floor(( today.getTime()
            - targetDate.getTime() ) / 86400000)
    var msg = "This is day number " + timeAfterTarget + " for this year."
    document.write(msg)
    //-->
    </SCRIPT>
    0
     
    LVL 5

    Author Comment

    by:snocross
    Heman, I need to do this in Javascript.  My validations and transit times are all calculated on the fly using Javascript.

    Qwaletee, I'm evaluating your code right now, thanks....
    0
     
    LVL 5

    Author Comment

    by:snocross
    I've been toying with your code and am having problems;

    With your code I can successfully do the following;

    TodaysDate - TargetDate = NumberOfDays
    (In this example I can calculate 'NumberOfDays' which is nice)

    but I can't seem to do what I want which is;

    TodaysDate + NumberOfDays = NewDate
    (I want to calculate this new date)

    Does this make sense?

    0
     
    LVL 31

    Expert Comment

    by:qwaletee
    getTime returns the numeric value of a datetime.  setTime, when applied to a dateTime object, changes that datetime object to represent the same datetime as the number representes.  That number goes up by one per millisecond.  So, see if this helps you:


    var second = 1000;
    var minute = second * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var today = new Date();
    var todayNumber = today.getTime();
    var tomorrowNumber = todayNumber + day;
    var monthLaterNumber = todayNumber + (day * 30);
    var tomorrow = new Date();
    tomorrow.setTime(tomorrowNumber);
    var monthLater = new Date()
    monthLater.setTime(monthLaterNumber);
    alert (today + " tomorrow " + tomorrow + " a month later " + monthLater);
    0
     
    LVL 31

    Accepted Solution

    by:
    I think this will work:

    target = new Date();
    target.setTime( (NumberOfDays*86400000) + new Date().getTime() );


    target now contains the date NumberOfDays in the future
    0
     
    LVL 5

    Author Comment

    by:snocross
    I have it;

    function DeliveryValidate()
    {xyz = document.forms[0].EstTurnaround.value;
    CurDate = new Date();
    CurDateB = new Date(CurDate.getTime()+(xyz * 86400000));
    alert(CurDateB)}
    0
     
    LVL 5

    Author Comment

    by:snocross
    Wow, that was pretty close to what I had and posted at the same time!!  The points are yours my friend!
    0
     
    LVL 46

    Expert Comment

    by:Sjef Bosman
    It seems I just missed the getTime()-call in my first response. For the rest I don't seem much difference. :(

    Sjef :)
    0
     
    LVL 5

    Author Comment

    by:snocross
    I'm sorry bosman!  I actually somehow totally missed your snipet of code!!  Thanks for your help, I really appreciate it.
    0
     
    LVL 31

    Expert Comment

    by:qwaletee
    Actually, you could probably reduce it to:
    CurDateB = new Date(new Date.getTime() + (xyz*86400000));
    0
     
    LVL 5

    Author Comment

    by:snocross
    Beautiful.  Thanks again.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
    Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now