By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,235 Members | 1,612 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,235 IT Pros & Developers. It's quick & easy.

Problems adding an extra day depending on time in an order form

P: 89
Hi' All

I have an ordering formular where users can choose on how many working days they want thier order on. I skip saturday and sunday because they are not working days and this works fine. If they place thier order after 3 o'clock in the afternoon an extra working day should be added. This also works fine in my script, but then the problem occurs. Instead of skipping staurday and sunday when they place their order after 3 o'clock, it skips sunday and monday. I use the below script to calculate and show the shipping date. Can anyone tell me what is wrong....

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function setDelivery(val) {
  3. var delivery = new Date(); // We start at the current date
  4. var theyear = delivery.getFullYear();
  5. var themonth = delivery.getMonth()+1;
  6. var theday = delivery.getDate();
  7. var thehours = delivery.getHours();
  8. var i = 0; 
  9. // i - The number of working days we have reached
  10. while (i < parseInt(val)) 
  11. // We continue until we have reached the desired working days
  12. {
  13. delivery.setDate(delivery.getDate() + 1); 
  14. // Always jump one day ahead
  15. if (delivery.getDay() != 0 && delivery.getDay() != 6) i++; 
  16. // If it is not a saturday or sunday we add a working day to i
  17. }
  18. if (delivery.getHours() >= 15){ 
  19. delivery.setDate(delivery.getDate() + 1); 
  20. }
  21. // Now delivery should contain the desired date.
  22. //you have the correct date...
  23. document.getElementById("shopform").shipdate.value = delivery.getDate() + "-" + (delivery.getMonth() + 1) + "-" + delivery.getFullYear();
  24. }
  25. // end Helpers -->
  26. </script>
Jan 22 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
there's maybe some problem after delivery.setDate(), every Date call after that is referencing the new date (btw. why do you have the current date values set when you don't use them?)
Jan 22 '09 #2

Post your reply

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