473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Add some time to a date script

26
I have the following script on my website. The idea is that the user puts in a date, say January 1st. The script has to figure what day they actually will graduate a course. The students enter Monday, Tues, Wed, or Thurs, and then graduate on the 7th Friday. (regardless of what day they enter)

However, I need to modify it so that if the "enter date" is beyond 25 oct 2008, they graduate on the 9th Friday.

Can anyone help? I appologize, I'm just not a script type.

Thank you!

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!-- Hide this code from non-JavaScript browsers
  3. function GradDate() {
  4. UDate=document.forms[0].entry.value; // pick up user entry
  5. i1=UDate.indexOf('/'); // find first slash
  6. i2=UDate.indexOf('/',i1+1); // ...second slash
  7. UDate_M=UDate.substring(0,i1); // everything before first slash
  8. UDate_D=UDate.substring(i1+1,i2); // ...between two slashes
  9. UDate_Y=UDate.substring(i2+1); // ...after second slash
  10. UDate_Y=UDate_Y*1+2000; // 2-digit year to 4-digit
  11. UDate_M=UDate_M-1; // jan-dec=0-11
  12. Now=new Date(UDate_Y,UDate_M,UDate_D); // convert to a date
  13. Now_D=Now.getDay(); // sunday-saturday=0-6
  14. Diff=47-Now_D; // seventh Friday later
  15. Factor=24*60*60*1000; // seconds per day
  16. Target=new Date(Now*1+Diff*Factor); // the target date
  17. Target_M=Target.getMonth();
  18. Target_D=Target.getDate();
  19. Target_Y=Target.getYear();
  20. if (Target_Y < 70) { Target_Y=Target_Y+2000; }
  21. if (Target_Y < 1900) { Target_Y=Target_Y+1900; }
  22. Target_M=Target_M*1+1; // Jan-Dec = 1-12
  23. Formatted=Target_M+'-'+Target_D+'-'+Target_Y;
  24. document.forms[0].result.value=Formatted; // display on the form
  25. }
  26. // End hiding -->
  27.  
Mar 28 '08 #1
3 1162
acoder
16,027 Expert Mod 8TB
Create a date object using the Date() constructor for the 25th of October and compare to the inputted date.

If it's greater than, add 14 days to the 7th Friday (to get the 9th Friday).
Apr 1 '08 #2
TVining
26
Thanks. Now for the big question....Where do I put that, and what would it look like?

:-P

Sorry, I'm script stupid.
May 31 '08 #3
acoder
16,027 Expert Mod 8TB
Heh, two months later ;)

Create a date and compare it with Now:
Expand|Select|Wrap|Line Numbers
  1. compareDate = new Date(2008,9,25);// Oct 25,2008
  2. //after declaring Now and Diff
  3. if (Now > compareDate) diff += 14;
May 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Harag | last post by:
Hi all I think this is in the wrong group but since I don't read others much or code in java script I was wondering if anyone could help me with this small problem, as I code mostly in ASP...
1
by: Treetop | last post by:
I used the following script for a site to stop displaying after a date / time, but it seems huge. Any ideas on how to make it shorter? There are many events in this list. function events() {...
17
by: Mike A | last post by:
Hi, I'm hoping someone can help me with this. I have a URL for which I'd like to limit access to by time. For example,say I have a URL that I don't want accessable on Monday mornings between...
4
by: James Bond 007 | last post by:
I am a novice to Javascript (can do simple text-based pop-ups, but not familiar with variable manipulation). I would like to have a Javascript that gives me the start time (I don't care about...
5
by: sandman | last post by:
I've been testing my web app on another workstation to simulate using the server time. The test pc's time is an hour behind the server time and when the user processes a request, the server time...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
6
by: D | last post by:
Hello all...I have an issue with one of my java script functions that I'm hoping someone can easily help with. I have a web based application that we use to create/sign up for overtime. When we...
15
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is viewed. Can anyone point out what mistakes there are...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
1
by: nigelesquire | last post by:
I am in need of your assistance. I have a page with multiple unixtime stamps and I need to display them in readable time and date with the user's time zone. Below is the code. <!DOCTYPE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.