469,289 Members | 2,155 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

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 1113
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

Post your reply

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

Similar topics

7 posts views Thread by Harag | last post: by
1 post views Thread by Treetop | last post: by
4 posts views Thread by James Bond 007 | last post: by
5 posts views Thread by sandman | last post: by
15 posts views Thread by Oleg Leikin | last post: by
6 posts views Thread by D | last post: by
15 posts views Thread by Cerebral Believer | last post: by
9 posts views Thread by LayneMitch via WebmasterKB.com | last post: by
1 post views Thread by nigelesquire | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.