473,326 Members | 2,081 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,326 software developers and data experts.

Comparing DateTime........please help

Hi all,
I am unable to write a javascript which will allow me to compare
datetime entered by the user with the current datetime.( i.e the
usertime should be less than or greater than currenttime)

Thanx a lot in advance
Jul 20 '05 #1
2 13470
prashanth wrote:
Hi all,
I am unable to write a javascript which will allow me to compare
datetime entered by the user with the current datetime.( i.e the
usertime should be less than or greater than currenttime)

Thanx a lot in advance


Here is a start... in this example, you can type two forms of the date
in the box:
January 20, 2004
January 20, 2004 10:30:22

Of course, they need to be entered in exactly, so you will likely set up
your form for better user input, and create the string yourself.

The date constructor has the following formats:
new Date("Month dd, yyyy hh:mm:ss")
new Date("Month dd, yyyy")
new Date(yy,mm,dd,hh,mm,ss) // where month is an integer
new Date(yy,mm,dd)
new Date(milliseconds) // milliseconds since January 1, 1970

Here is the code I came up with... play with it how you need:

<HTML>
<HEAD>
<SCRIPT>
function compareDate()
{
var currentDate = new Date();
var userDate =
new Date(document.getElementById("user_date").value);

if(userDate <= currentDate)
alert("SUCCESS");
else
alert("FAILURE");

return false;
}
</SCRIPT>
</HEAD>

<BODY>
<FORM>
<INPUT TYPE=text ID=user_date>
<INPUT TYPE=submit onClick="return compareDate();">
</FORM>
</BODY>
</HTML>

Jul 20 '05 #2
JRS: In article <40********@10.10.0.241>, seen in
news:comp.lang.javascript, Brian Genisio <Br**********@yahoo.com> posted
at Wed, 21 Jan 2004 07:47:40 :-
prashanth wrote:
I am unable to write a javascript which will allow me to compare
datetime entered by the user with the current datetime.( i.e the
usertime should be less than or greater than currenttime)

Thanx a lot in advance


Here is a start... in this example, you can type two forms of the date
in the box:
January 20, 2004
January 20, 2004 10:30:22

Of course, they need to be entered in exactly, so you will likely set up
your form for better user input, and create the string yourself.

The date constructor has the following formats:
new Date("Month dd, yyyy hh:mm:ss")
new Date("Month dd, yyyy")
new Date(yy,mm,dd,hh,mm,ss) // where month is an integer

one smaller than normalnew Date(yy,mm,dd)
new Date(milliseconds) // milliseconds since January 1, 1970

GMT

The above is not a complete list.

OP: you don't give an area-of-use. The code already given will accept,
I believe, both 17/03/04 and 03/17/04 as St Patrick's Day; but not
17/03/04, which is what is most generally used for that date.
Therefore, the form should not be encouraged. 2004/03/17 is safe.

To validate as being a proper date, see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
1
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
2
by: Gawn | last post by:
Hi I am from Thainald and new to PHP/MySQL. I am doing a news website and I can't do the related news, while I can for latest news. My code for latest news is "SELECT * FROM news WHERE...
0
by: Payodhi | last post by:
Hi, I am generating text file.I have written bellow code........ Imports System.IO Dim sw As StreamWriter Dim strRecord,filenam As String Protected Sub BtnTextFile_Click(ByVal sender As...
6
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm just trying to test datetime functions: DateTime dt1 = "9/15/2007"; DateTime dt2 = "9/17/2007"; DateTime dtResult; dtResult = dt2 - dt1; The above is what i'm trying to say...
3
by: skris | last post by:
Hi All, I have some contents in a file named Msg.txt. I need to append the date right after the end of every line of that file. I tried out this code, but it did not work. >>> import datetime...
4
by: jupi13 | last post by:
i have this code..i don't know what where is the error in this one..it says data type mismatch..... Dim Mydate As Date Dim MydateString As String MydateString = "Text1.Text" Mydate =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.