473,379 Members | 1,337 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,379 software developers and data experts.

add an extra day depending on time

Hi' All

I have an ordering formular where users can choose on have many days they want their order on. I use the below script to calculate and show the shipping date:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function setDelivery(val) {
  3. var delivery = new Date(); // We start on current day
  4. var theyear = delivery.getFullYear();
  5. var themonth = delivery.getMonth()+1;
  6.  
  7. var i = 0; // i - Number of working days we have reached
  8.  
  9. while (i < parseInt(val)) // We continue until we have reached the desired number of working days
  10. {
  11.     delivery.setDate(delivery.getDate() + 1); // Always jump one day ahead
  12.     if (delivery.getDay() != 0 && delivery.getDay() != 6) i++; // Provided that it is not a saturady or sunday we add a working day to i
  13. }
  14.  
  15. // Now "delivery" should contain the desired date.
  16.  
  17.  //you have the correct date...
  18. document.getElementById("shopform").shipdate.value = delivery.getDate() + "-" + (delivery.getMonth() + 1) + "-" + delivery.getFullYear();
  19. }
  20. // end Helpers -->
  21. </script> 
What i want the script to do as an extra thing is to add one day extra, to the days already added, if the user uses the ordering formular after 3 p.m. Can this be done...???

Example:

A user orders at 4 p.m. on the 24th of November and wants the order on 2 days. So instead of delivery date being the 26th of November it should be the 27th of November...
Nov 24 '08 #1
3 1416
acoder
16,027 Expert Mod 8TB
Use getHours() to get the current hour. If it's greater than 15 (3pm), then add the extra day.
Nov 24 '08 #2
Hi'

Tried doing what you suggested and my code looks like this now:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function setDelivery(val) { 
  3. var delivery = new Date(); // We start on current day 
  4. var theyear = delivery.getFullYear(); 
  5. var themonth = delivery.getMonth()+1;
  6. var thehours = delivery.getHours(); 
  7.  
  8. var i = 0; // i - Number of working days we have reached 
  9.  
  10. while (i < parseInt(val)) // We continue until we have reached the desired number of working days 
  11.     delivery.setDate(delivery.getDate() + 1); // Always jump one day ahead 
  12.     if (delivery.getDay() != 0 && delivery.getDay() != 6) i++; // Provided that it is not a saturady or sunday we add a working day to i 
  13.     if (delivery.getHours() >= 15) i++;
  14.  
  15. // Now "delivery" should contain the desired date. 
  16.  
  17.  //you have the correct date... 
  18. document.getElementById("shopform").shipdate.value = delivery.getDate() + "-" + (delivery.getMonth() + 1) + "-" + delivery.getFullYear(); 
  19. // end Helpers --> 
  20. </script>
But this actually subtracts a day instead of adding a day.... Could you perhaps tell me what i'm doing wrong....????

Thanks!
Nov 25 '08 #3
acoder
16,027 Expert Mod 8TB
Rather than incrementing 'i', you need to set the date. Better still, work out the number of days separately and then just set the date at the end (outside the loop).
Nov 25 '08 #4

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

Similar topics

2
by: Nick | last post by:
In VS 2003 and VS 2005 beta 2 I am trying to write a simple program. It has a datagrid and a textbox along with a menubar. There is a command in the menu bar which is "Run Query" and has the...
0
by: Wilford Fleming | last post by:
----9379157466zdit8167 Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html><head><META http-equiv=3D"Bulletin-Date" content=3D"TYPE-HTTP"><META=...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
0
by: pei_world | last post by:
I am using the following code to configurate my datagrid and load data from my Pocket Access Database. however, I got some more row extra, and it is the number I setted with my object array in my...
2
by: David Union | last post by:
Hi. I'm posting this here because I don't know exactly what the best group is. This is for an aspx page with Visual Basic as the code-behind page. I am doing very simple code... in the middle...
15
by: James Black | last post by:
If you go to http://dante.acomp.usf.edu/HomeworkAssistant/index.php you will see my code. Type in: s = a + b and hit tab, and you will see the extra words. How do I remove these? Here is a...
5
by: dw | last post by:
hello - first, let me state that i am an Asp.Net rookie. here is the situation: i have a page that looks good in the vs.net designer, but when the page renders there are extra amounts...
2
by: ricky | last post by:
Can anybody help with the function to get rid of extra characters in the file. I want to remove the string from the file.So i read from input file and pass the string say "john" if found dnt write...
1
by: printline | last post by:
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.