<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
<!--
function check (f) {
var start = new Date (f.start.value);
var end = new Date (f.end.value);
start.setDate (start.getDate() + 28);
if (end >= start) {alert (); return false}
}
// -->
</script>
<style type="text/css">
<!--
fieldset {padding:1ex; width:10em}
label {display:block; margin:1em 0}
input {display:block}
button {display:block; margin:auto}
-->
</style>
</head>
<body>
<form action="some-script.pl" onsubmit="return check (this)">
<fieldset>
<legend>Dates</legend>
<label>Start Date<input name="start" onchange="this.value = new Date (this.value).toDateString()" type="text"></label>
<label>End Date<input name="end" onchange="this.value = new Date (this.value).toDateString()" type="text"></label>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Nope. In the second he solved your date format dd/mm/yyyy
Actually, the second one will take most any date format.
The native Date constructor is supposed to work with multiple formats, but just which ones is not specified. Implimentation may be locale dependent. In the US dd/mm/yyyy isn't supported to make room for our mm/dd/yyyy. Try the first one in England, just for kicks, but the second one will always work with that format. If you feed it another format then it defers to the native constructor.
Try my second one with a few other formats and you'll see another feature.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Thanks guy. but it doesn't work I've put in 31/03/2005 for both start and end date but when displaying it I get "Wed Aug 1 00:00:00 UTC +0100 2007" and "Tue Jul 3 00:00:00 UTC +0100 2007"
Any idea? Do I need to convert the dates before I compare them?
It would seem that you haven't properly copied my example.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
gregDate = new Date(isDate);
year = gregDate.getFullYear();
month = gregDate.getMonth()+1;
day = gregDate.getDate();
A = Math.floor((7*(year+Math.floor((month+9)/12)))/4);
B = day+Math.floor((275*month)/9)
isJulian = (367*year)-A+B+1721014;
return isJulian;
}
if (fwdDate-refDate > 28 || fwdDate <= refDate)
{
alert('Date2 Must not be more than 28 days later than Date1');
document.forms.Form1.nDate2.value = "";
document.forms.Form1.nDate2.focus();
}
}
<script type="text/javascript">
<!--
alert (new Date ('April, 4 2005') >= new Date ('2005, May, 9'))
// -->
</script>
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
Actually, the second one will take most any date format.
The native Date constructor is supposed to work with multiple formats, but just which ones is not specified. Implimentation may be locale dependent. In the US dd/mm/yyyy isn't supported to make room for our mm/dd/yyyy. Try the first one in England, just for kicks, but the second one will always work with that format. If you feed it another format then it defers to the native constructor.
Try my second one with a few other formats and you'll see another feature.
Date Object
Enables basic storage and retrieval of dates and times.
dateObj = new Date()
dateObj = new Date(dateVal)
dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])
Arguments
dateObj Required. The variable name to which the Date object is assigned.
dateVal Required. If a numeric value, dateVal represents the number of milliseconds in Universal Coordinated Time between the specified date and midnight January 1, 1970. If a string, dateVal is parsed according to the rules in the parse method. The dateVal argument can also be a VT_DATE value as returned from some ActiveX® objects.
Anything is possible, how much it will cost is another matter...
Bookmarks