473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Help with check date and hours

263 100+
Help with check date and hours

Hi all.

I have this form:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4.  
  5. </head>
  6.  
  7. <body>
  8.  
  9. <form name="orario" method="post" action="">
  10.  
  11. <input type="text" name="hour" size="20">
  12.  
  13. <input type="text" name="dates" size="20">
  14.  
  15. <input type="submit" value="Invia" name="B1">
  16.  
  17. </form>
  18. </body>
  19.  
  20. </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
Sep 22 '08 #1
10 1975
RamananKalirajan
608 512MB
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
Sep 22 '08 #2
viki1967
263 100+
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?
Sep 22 '08 #3
acoder
16,027 Expert Mod 8TB
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.
Sep 22 '08 #4
viki1967
263 100+
Hi acoder; one example please?
Sep 22 '08 #5
acoder
16,027 Expert Mod 8TB
This link should help get you started.
Sep 22 '08 #6
viki1967
263 100+
This link should help get you started.
No, I dont no... I dont understand your suggestion...
Sep 22 '08 #7
acoder
16,027 Expert Mod 8TB
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.
Sep 22 '08 #8
viki1967
263 100+
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... :

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. <!--
  3.  
  4. function controllo_data(stringa){
  5.         var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
  6.           if (!espressione.test(stringa))
  7.           {
  8.             return false;
  9.           }
  10.       else{
  11.              anno = parseInt(stringa.substr(6),10);
  12.              mese = parseInt(stringa.substr(3, 2),10);
  13.              giorno = parseInt(stringa.substr(0, 2),10);
  14.  
  15.          var data=new Date(anno, mese-1, giorno);
  16.                if(data.getFullYear()==anno && data.getMonth()+1==mese && data.getDate()==giorno){
  17.                     return true;
  18.                 }
  19.            else{
  20.                  return false;
  21.                }
  22.            }
  23. }
  24.  
  25. function confronta_data(data1)
  26.  
  27. {
  28.     dataCorr = new Date();
  29.     giorno = dataCorr.getDate();
  30.     mese = dataCorr.getMonth();
  31.     anno = dataCorr.getYear();
  32.     data = anno+mese+giorno;
  33.  
  34.         if(controllo_data(data1))
  35.  
  36.         {
  37.  
  38.           data1str = data1.substr(6)+data1.substr(3, 2)+data1.substr(0, 2);
  39.  
  40.  
  41.       if (data1str-data<0) 
  42.  
  43.       {
  44.                 alert("Error Date");
  45.           }
  46.         }
  47.  
  48. else{
  49.        alert("KO");
  50.        document.orario.ggInizio.focus();
  51.        return false;
  52.         }
  53.  
  54. }
  55.  
  56.  
  57. //-->
  58.  
  59. </script>
  60.  
  61. </HEAD>
  62. <BODY>
  63.  
  64. <form name="orario" method="POST" action="" onSubmit="return confronta_data(this);">
  65.  
  66. <input type="text" name="ggInizio" size="10">
  67.  
  68. <input type="submit" value="Invia" name="B1">
  69.  
  70.  
  71. </form>
  72. </BODY>
  73. </HTML>
Sep 22 '08 #9
acoder
16,027 Expert Mod 8TB
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().
Sep 23 '08 #10
RamananKalirajan
608 512MB
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
Sep 23 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
2
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...
13
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...
9
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...
3
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 ...
6
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...
2
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...
9
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...
3
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
jinu1996
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.