PDA

View Full Version : getmonth() help

chrisboots
01-20-2012, 05:37 PM
i am making a hire script for my website, we have a summer and a winter rate for hires over 28 days, so if the month is between march and September its one price ( sting 9) and if its not then its sting 8.

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(',');
m = new Date (document.date.firstDate.value);
month = m.getMonth();
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;}

if (month > 3 < 8 && day ==28) {total = (groupstring[9];}

Philip M
01-20-2012, 05:45 PM
So what is your question? Are you asking how to get the month in Javascript?

var month = new Date().getMonth(); // months in Javascript are 0-11, so March is month 2 and September month 8.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

chrisboots
01-20-2012, 05:50 PM
So what is your question? Are you asking how to get the month in Javascript?

var month = new Date().getMonth(); // months in Javascript are 0-11, so March is month 2 and September month 8.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

i have tried using getdate() but i can only get it to work in mm/dd/yyyy fromat, where as im usning dd/mm/yyyy format. reading over my post and its not as clear as i thought, i now know i need to use getdate() but as i said, i use dd/mm/yyyy so it dose not work

Philip M
01-20-2012, 05:54 PM
getDate() returns the date (i.e 20 today), not the month. And note that Javascript is case-sensitive - getdate() will return an error.

You can format the date any way you like:-

var now = new Date();
var yr = now.getFullYear();
var mth = now.getMonth();
var dt = now.getDate();

alert (dt + "/" + (mth+1) + "/" + yr); // 20/1/2012

chrisboots
01-20-2012, 06:10 PM
ill try to be clearer about what i need. on the webpage is a date picker, which give the date in the format dd/mm/yyyy. I need to get the MM value from that output, so that i can use that to tell the script weather to use the summer/winter rate. here is the webpage for reference

<!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">
<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 ................................. -->

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

xelawho
01-20-2012, 06:32 PM
assuming that you want to use the date from the firstdate text box, you can do something like this:

function checkMonth() {
mon=document.getElementById("firstDate").value.split("/")[1]
if(mon>5 && mon<12){rate="winter"} else {rate="summer"}
return rate;
}

Philip M
01-20-2012, 07:43 PM
assuming that you want to use the date from the firstdate text box, you can do something like this:

function checkMonth() {
mon=document.getElementById("firstDate").value.split("/")[1]
if(mon>5 && mon<12){rate="winter"} else {rate="summer"}
return rate;
}

Strange seasons you have in NL!

if (mon>=3 && mon<=9){rate="summer"} else {rate="winter"} // summer is March - September inclusive

xelawho
01-20-2012, 07:53 PM
where's NL? (although I do admit that I just made those months up... I figured chrisboots knows his winter period better than us...)

Philip M
01-21-2012, 08:59 AM
where's NL? (although I do admit that I just made those months up... I figured chrisboots knows his winter period better than us...)

Oh, my mistake. :o I thought you resided in the Netherlands.