|
-
Feb 2nd, 2005, 09:13 AM
#1
Thread Starter
Hyperactive Member
time validation in javascript
Hi all,
I want to be able to compare to given times on a web page and if they less than 1 hour apart or if they time they have entered is before the actual time I want it to display an alert. How do I do this, I managed it in php however I had the problem that it used the server time which is based in the US and the client time which was UK....
This is how I did my php version if any one is able to help with a javascript one I would be very gratful.
PHP Code:
$timenow=$_POST['theTime']; //javascript time
// This is the javascript time broken down into sperate parts and glued backtogeather as seconds
$time3 = "{$timenow}"; //set the time portion as a variable
$time4 = explode(":",$time3); //seperate the time portion
//convert to seconds
$javahours=($time4[0] * 3600);
$javaminutes=($time4[1] * 60);
//get total amount of seconds
$javatimeinseconds = $javahours + $javaminutes;
// now do it for the alarm time.
$alarmhours=($alarm1 * 3600);
$alarmminutes=($alarm2 * 60);
$alarmtimeinseconds = $alarmhours+$alarmminutes;
//do the calculation to get the time difference.
$timedifference = ($alarmtimeinseconds - $javatimeinseconds);
//if ($alarmtimeinseconds < $javatimeinseconds) {
// die('<html>
// <head>
// <title>www.wakemeup.co.uk - - ALARM TIME BEFORE ACTUAL TIME.</title>
// </head>
// <body>
// <p align="center"><font face="Century Gothic">You are trying to set a reminder in the past please try again.</font></p>
// <p align="center"><font face="Century Gothic"><a href="newentry.php"><img src="images/new.jpg" width="220" height="36" border="0"></a></font> </p>
// <p align="center"> </p>
// </body>
// </html>');
//}
//if ($timedifference < 3600) {
// die('<html>
// <head>
// <title>www.wakemeup.co.uk - - NOT ENOUGH NOTICE.</title>
// </head>
// <body>
// <p align="center"><font face="Century Gothic">Sorry but you must give at least 1 hours notice in order to set a reminder please try again</font></p>
// <p align="center"><font face="Century Gothic"><a href="newentry.php"><img src="images/new.jpg" width="220" height="36" border="0"></a></font> </p>
// <p align="center"> </p>
// </body>
// / </html>');
//}
-
Feb 2nd, 2005, 11:07 PM
#2
Re: time validation in javascript
Have a look at this Javascript Date/Time FAQ. You should be able to find example of what you need there.
http://developer.irt.org/script/date.htm
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|