Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Increment date using javascript

Posted on 2004-10-22
15
Medium Priority
?
5,268 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
Comment
Question by:snocross
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +1
15 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12380336
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
ID: 12380404
Doesn't notes field calculation (using @Adjust) do the same job !

~Hemanth
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12380536
Yep, but not immediately on-screen, and I suppose that's the idea
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 12380571
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
ID: 12383776
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
ID: 12402508
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
ID: 12403104
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
ID: 12403849
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:
qwaletee earned 500 total points
ID: 12404015
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
ID: 12404192
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
ID: 12404241
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
ID: 12404468
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
ID: 12404502
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
ID: 12404982
Actually, you could probably reduce it to:
CurDateB = new Date(new Date.getTime() + (xyz*86400000));
0
 
LVL 5

Author Comment

by:snocross
ID: 12405086
Beautiful.  Thanks again.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

636 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