Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Time difference help

    Hi, back for more help

    Im doing a hire price script for my works website, i have two time input input boxes using <select> function. I need a script to figure out the time diffrence between the two times, and if the second time is 3 or more hours before the first time it adds a days charge, well, it dosent even need to figure out the exact difference between the two, only need to see if the second is > by 3 or more, here is my script

    Code:
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" profile="http://gmpg.org/xfn/11">
    <head>
    	<meta http-equiv="Content-Type" content="UTF-8" />
    	<title>Car Hire Ottershaw | Van Hire Ottershaw | Car Rental | Van Rental </title>
    	<meta name="keywords" content="Car Hire Ottershaw, Surrey, Van Rental Ottershaw, Van Hire Ottershaw, Car Rental Ottershaw,  " />
    	<link rel="stylesheet" href="layout-ff.css" type="text/css" media="screen, projection" />
    	<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
    
    	<!-- put java here................................. -->
    <script language="javascript" type="text/javascript" src="datetimepicker.js">
    
    //Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
    //Script featured on JavaScript Kit (http://www.javascriptkit.com)
    //For this script, visit http://www.javascriptkit.com 
    
    </script>
    
    	<!-- stop java here ................................. -->
    
    	</head>
    	<body>
    
    		<!-- content ................................. -->
    		<form name="date">
    			<select name="car" id="car">
    				<option value="A">Manual Panda / Auto Smart</option>
    				<option value="B">Manual Clio 3 3Dr or 5 Dr / Manual Picanto</option>
    				<option value="CD">Manual Rio / Clio 1.2T / Auto Picanto</option>
    				<option value="E">Manual Venga / Auto Rio</option>
    				<option value="F">Auto Focus / Cee'd / Manual Megane</option>
    				<option value="G">Auto Cee'd Estate / Manual Megane Estate</option>
    				<option value="H">Auto Mondeo</option>
    				<option value="I">Manual Sportage 2WD</option>
    				<option value="J">Auto Sportage 4X4</option>
    				<option value="K">Auto Galaxy / Manual RCZ</option>
    				<option value="L">Auto Sorento 4X4</option>
    				<option value="M">Manual Kangoo Van</option>
    				<option value="O">Manual LWB LL29 Trafic</option>
    			</select>
    
    			
    			
    			
    			<p>start date:</p>
    			<input id='firstDate' type="text" size="25"><a href="javascript:NewCal('firstDate','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
    			<p>Start Time:
    			<select name="time1" id="time1">
    				<option value="1">08:00</option>
    				<option value="2">08:30</option>
    				<option value="3">09:00</option>
    				<option value="4">09:30</option>
    				<option value="5">10:00</option>
    				<option value="6">10:30</option>
    				<option value="7">11:00</option>
    				<option value="8">11:30</option>
    				<option value="9">12:00</option>
    				<option value="10">12:30</option>
    				<option value="11">01:00</option>
    				<option value="12">01:30</option>
    				<option value="13">02:00</option>
    				<option value="14">02:30</option>
    				<option value="15">03:00</option>
    				<option value="16">03:30</option>
    				<option value="17">04:00</option>
    				<option value="18">04:30</option>
    				<option value="19">05:00</option>
    				<option value="20">05:30</option>
    				<option value="21">06:00</option>
    				<option value="22">06:30</option>
    				<option value="23">07:00</option>
    				<option value="24">07:30</option>
    				
    			</select>
    			
    			<p>end date:</p>
    			<input id='secondDate' type="text" size="25"><a href="javascript:NewCal('secondDate','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
    			
    			<p>End Time:
    			<select name="time2" id="time2">
    				<option value="1">08:00</option>
    				<option value="2">08:30</option>
    				<option value="3">09:00</option>
    				<option value="4">09:30</option>
    				<option value="5">10:00</option>
    				<option value="6">10:30</option>
    				<option value="7">11:00</option>
    				<option value="8">11:30</option>
    				<option value="9">12:00</option>
    				<option value="10">12:30</option>
    				<option value="11">01:00</option>
    				<option value="12">01:30</option>
    				<option value="13">02:00</option>
    				<option value="14">02:30</option>
    				<option value="15">03:00</option>
    				<option value="16">03:30</option>
    				<option value="17">04:00</option>
    				<option value="18">04:30</option>
    				<option value="19">05:00</option>
    				<option value="20">05:30</option>
    				<option value="21">06:00</option>
    				<option value="22">06:30</option>
    				<option value="23">07:00</option>
    				<option value="24">07:30</option>
    				
    			</select>
    			
    			<p>Days:</p>
    			<input type="text" name="days" />
    
    			<p>Price:</p>                                      
    			<input type="text" name="rentalamount" />   
    			<p>Deposit:</p>                                
    			<input type="text" id="depo" name="depo" />  
    			<p>Excess mile price</p>			
    			<input type="text" name="mile" /> 
    			
    
    			<p><input type="button" value="Quote" onclick="dateDiff() ;calculate() ;deposit() ;milecharge() ;agecheck()" />
    			<INPUT TYPE=RESET name="clear" value="Clear Form"/></p> 
    
    		</form>
    		
    		<p> GAV: Deposit and mile excess now working, 28 days now works and now have a reset button also made a pop up for age restriction(select sportage/galaxy/rcz
    	) all prices are now on here now all to do is set up cecks on the dates ( summer/ winter. collect before return e.c.t) im starting to like this java script **** !</p>
    		<!-- /content -->
    
    	</body>
    
    </html>

    thanks

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Confused ... in the first sentence you say
    "second time is 3 or more hours before the first time"
    which makes time2<time1. But later you state
    "need to see if the second is > by 3 or more"
    which would mean that time2>time1. Which one is correct?

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    Confused ... in the first sentence you say

    which makes time2<time1. But later you state

    which would mean that time2>time1. Which one is correct?


    sorry put the > the wrong way if time2 if GREATER than time1 by 3 or more hours, then it adds a day to the price
    Last edited by chrisboots; 01-20-2012 at 02:15 PM.

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Then its an easy one. As you can see the difference between the VALUEs of the selects has to be greater or equal 6 to have 3 or more hours difference

    Example: time1 selected "08:30" and time2 selected "12:00". The value for time1 will be "2" and for time2 it will be "9". The integer difference between those two values is 7 which is greater than 6. So the time difference is >= 3 hours

    Code:
    var time1 = parseInt(document.getElementById('time1').value, 10);
    var time2 = parseInt(document.getElementById('time2').value, 10);
    if(time2-time1 >= 6) {
       // add day here
    }

  • Users who have thanked devnull69 for this post:

    chrisboots (01-20-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    Then its an easy one. As you can see the difference between the VALUEs of the selects has to be greater or equal 6 to have 3 or more hours difference

    Example: time1 selected "08:30" and time2 selected "12:00". The value for time1 will be "2" and for time2 it will be "9". The integer difference between those two values is 7 which is greater than 6. So the time difference is >= 3 hours

    Code:
    var time1 = parseInt(document.getElementById('time1').value, 10);
    var time2 = parseInt(document.getElementById('time2').value, 10);
    if(time2-time1 >= 6) {
       // add day here
    }
    Thanks, but i cant get it to work for some reason, can you help? here is my java code for the days

    Code:
     <!-- price calculation
    		function calculate()
    	{
    		var
    			days = parseInt('0' + document.date.days.value, 10),
    			groupstring, total = 0;
    <!-- 1 day, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days, 28 DaySummer, 28 DayWinter, Excess Amount, excess miles................................. -->
    		switch (document.date.car.value) {
    			case 'A': groupstring = '2500,5000,7500,10000,12500,12800,13000,45000,42000,25000,10';  break;<!--PANDA/SAMRT -->
    			case 'B': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10';  break;<!--CLIO 3/5/MAN PIC -->
    			case 'CD': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10';  break;<!-- RIO CLIO T PIC AUTO-->
    			case 'E': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10';  break;<!-- VENGA RIO AUTO-->
    			case 'F': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15';  break;<!-- FOCUS/MEGANE/CEED-->
    			case 'G': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,25000,15'; break;<!--ESTATE -->
    			case 'H': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15'; break;<!-- -MONDEO->
    			case 'I': groupstring = '4500,8000,12000,16000,20000,24000,25000,75000,65000,40000,15'; break;<!--2WD SPORTAGE -->
    			case 'J': groupstring = '5000,9000,13500,18000,22500,26000,27000,80000,80000,40000,15'; break;<!--4WD SPORTAGE -->
    			case 'K': groupstring = '6500,11000,16500,22000,27500,30000,31000,950000,82500,40000,15'; break;<!--GLA + RCZ -->
    			case 'L': groupstring = '7000,12000,18000,24000,30000,35000,360000,120000,1200000,25000,15'; break;<!-- SORENTO-->
    			case 'M': groupstring = '2650,5300,7950,10600,13250,14600,15000,49900,48000,25000,10'; break;<!-- KANGOO-->
    			case 'O': groupstring = '4100,8200,12300,16400,20500,20800,21000,75000,72500,40000,15'; break;<!-- TRAFIC-->
    		}
    		groupstring = groupstring.split(',');
    
    		if (days > 0 && days < 8) {total =  groupstring[days - 1];     } else
    		if (days < 28)            {total = (groupstring[6] / 7) * days;} else
    		if (days === 28)          {total =  groupstring[8];}
    		if (days > 28)   		  {total = (groupstring[8] / 28) * days;}
    			
    			
    			
    			document.date.rentalamount.value = "£" + (Math.round(total) / 100).toFixed(2);
    
    		}
    		
    <!-- DATE DIFFRENCE
    
    function dateDiff() {
    
    t1 = document.date.firstDate.value;
    t2 = document.date.secondDate.value;
    
    var one_day=1000*60*60*24; 
    var x=t1.split("/"); 
    var y=t2.split("/");
    //date format(Fullyear,month,date) 
    var date1=new Date(x[2],(x[1]-1),x[0]);
    var date2=new Date(y[2],(y[1]-1),y[0])
    var month1=x[1]-1;
    var month2=y[1]-1;
    var Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
    document.date.days.value = (Diff +" days");;
    }
    // End -->


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •