Help with check date and hours
Hi all.
I have this form: - <html>
-
-
<head>
-
-
</head>
-
-
<body>
-
-
<form name="orario" method="post" action="">
-
-
<input type="text" name="hour" size="20">
-
-
<input type="text" name="dates" size="20">
-
-
<input type="submit" value="Invia" name="B1">
-
-
</form>
-
</body>
-
-
</html>
I need one function javascript check date and time insert in the form.
If date is same the date now and the hour is less two hours the hours now, the form is stopped.
For example:
date now = 22/09/2008
hours now = 14:50
date = 22/09/2008
hours = 15:30 ===> KO
date = 22/09/2008
hours = 16:49 ===> KO
date = 22/09/2008
hours = 16:50 ===> OK
Can you help me?
kind regards
viki
10 1975
hi Viki, can u please explain ur requirement clearly, if the time is lesser than the current time what should be done. I am not getting that point. can u please post it clearly.
Regards
Ramanan Kalirajan
hi Viki, can u please explain ur requirement clearly, if the time is lesser than the current time what should be done. I am not getting that point. can u please post it clearly.
Regards
Ramanan Kalirajan
Hi thanks x your answer.
I check this:
* Date register is same at today;
* Hours register is less two hours the now
Do you understand?
Create a new Date object which will default to the current date and time. Then you can compare by creating another Date object using the input.
Hi acoder; one example please?
This link should help get you started.
No, I dont no... I dont understand your suggestion...
Which part do you not understand? It shows how to create a Date object, it shows how you can set a date, and shows how to compare. OK, since you want to compare time, you will also need to set the time which you can do with setHours/setMinutes/setSeconds - see a full reference.
Which part do you not understand? It shows how to create a Date object, it shows how you can set a date, and shows how to compare. OK, since you want to compare time, you will also need to set the time which you can do with setHours/setMinutes/setSeconds - see a full reference.
OK, I try this but not working... : - <script language="javascript">
-
<!--
-
-
function controllo_data(stringa){
-
var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
-
if (!espressione.test(stringa))
-
{
-
return false;
-
}
-
else{
-
anno = parseInt(stringa.substr(6),10);
-
mese = parseInt(stringa.substr(3, 2),10);
-
giorno = parseInt(stringa.substr(0, 2),10);
-
-
var data=new Date(anno, mese-1, giorno);
-
if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
-
return true;
-
}
-
else{
-
return false;
-
}
-
}
-
}
-
-
function confronta_data(data1)
-
-
{
-
dataCorr = new Date();
-
giorno = dataCorr.getDate();
-
mese = dataCorr.getMonth();
-
anno = dataCorr.getYear();
-
data = anno+mese+giorno;
-
-
if(controllo_data(data1))
-
-
{
-
-
data1str = data1.substr(6)+data1.substr(3, 2)+data1.substr(0, 2);
-
-
-
if (data1str-data<0)
-
-
{
-
alert("Error Date");
-
}
-
}
-
-
else{
-
alert("KO");
-
document.orario.ggInizio.focus();
-
return false;
-
}
-
-
}
-
-
-
//-->
-
-
</script>
-
-
</HEAD>
-
<BODY>
-
-
<form name="orario" method="POST" action="" onSubmit="return confronta_data(this);">
-
-
<input type="text" name="ggInizio" size="10">
-
-
<input type="submit" value="Invia" name="B1">
-
-
-
</form>
-
</BODY>
-
</HTML>
You forgot the time part. Add the user inputted hours and minutes to the Date object too. When comparing, you can add 2 hours to the now date using setHours().
Hi Viki, u can do it very well in this way.
[HTML]var usrDate = new Date(year,month,day,hour*,min*,sec*,milli* );[/HTML]
This is a parameterized constructor which will return u a date object.
Note: The args with * are optional one but it will be useful for u to create a date obj with user given hour and minutes. Any soubts post back i will try to help u out.
Regards
Ramanan Kalirajan
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ralph Freshour |
last post by:
What's a good way to calculate the number of days between two dates in
the following format:
2003-07-15
2003-08-02
I've looked at the PHP date functions but I'm still a bit lost...
|
by: Little PussyCat |
last post by:
Excuse me for not putting a better name to this but I cannot think of a
suitable subject title!
anyway, here's what I am trying to do
At work we have a fair amount of data that is to do with...
|
by: Mike |
last post by:
Normally scheduling a job is a very elementary operation but for some
hidden reason I've been unable to schedule a job
which runs on a 28 day cycle, even though I have at least 16 other jobs...
|
by: tym |
last post by:
HELP!!!
I'm going round the twist with this...
I have a VB6 application which is using DAO to access a database
(Please - no lectures on ADO, I know what I'm doing with DAO!!)
Ok, problem...
|
by: christian |
last post by:
HI all!!
Does anybody knows a function that will allow me to do the following
in a form:
StartTime StopTime TotalHours NO LUNCH(this is a Check Box)
8:00 03:00pm 07:00
...
|
by: D |
last post by:
Hello all...I have an issue with one of my java script functions that
I'm hoping someone can easily help with. I have a web based application
that we use to create/sign up for overtime. When we...
|
by: vrkamalakar |
last post by:
Hi,
I got a scenario where the user gets an id which will expire in 24 hours. Now for that validation I need to update a field ie., set expiration time for 24 hours from the current time.
When...
|
by: pic078 via AccessMonster.com |
last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files)
that remains stuck in task manager after exiting the application - you can't
reopen database after exiting as a result...
|
by: lucky33 |
last post by:
My employer has asked me to create a database that will keep track of
the employee attendance. Time off / Time earned, excused / unexcused,
etc.
At my company from the 6th month of employment to...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |