473,804 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing two 12hr time fields

I am sorry if this has been asked before, but I looked all over for
exactly what I need, before asking you guys. I know that it has
something to do with the Date object, but I'm not sure how to
manipulate it.

I have 2 input fields, startTime, and finishTime.
The times need to be entered like 7:30am or 11:36pm.

All I want is to subtract the finishTime from the startTime to see how
long something took. I almost had it once, except that if I entered
the following:
startTime="7:00 am" and finishTime="1:0 0am" (next day), it displayed "6
hours", instead of "18 hours".

I know that this should be real easy, but I just can't find this
solution, and I've been to alot of sites.

Could someone please post a snippet that can do this, or at least a
link to a page that has one. Thanks.
Jul 23 '05 #1
4 3338
M.i.r.a.g.e. wrote on 30 aug 2004 in comp.lang.javas cript:
I am sorry if this has been asked before, but I looked all over for
exactly what I need, before asking you guys. I know that it has
something to do with the Date object, but I'm not sure how to
manipulate it.

I have 2 input fields, startTime, and finishTime.
The times need to be entered like 7:30am or 11:36pm.

All I want is to subtract the finishTime from the startTime to see how
long something took. I almost had it once, except that if I entered
the following:
startTime="7:00 am" and finishTime="1:0 0am" (next day), it displayed "6
hours", instead of "18 hours".

I know that this should be real easy, but I just can't find this
solution, and I've been to alot of sites.

Could someone please post a snippet that can do this, or at least a
link to a page that has one. Thanks.


If you really must use this antiquated form of time notation,
show us the code of your present attempt.
Rather than just coding for you,We better try to improve your own ideas,
if reasonably good.

btw,
did you look at the faq yet?
is the finish always after the start and no more than 24 hours apart?
Do we define a day as 24 hours without summertime switch hour?

-
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
JRS: In article <eb************ **************@ posting.google. com>,
dated Mon, 30 Aug 2004 09:34:13, seen in news:comp.lang. javascript,
M.i.r.a.g.e. <Wi*********@ho tmail.com> posted :
I am sorry if this has been asked before, but I looked all over for
exactly what I need, before asking you guys. I know that it has
something to do with the Date object, but I'm not sure how to
manipulate it.
Can you explain how it was that the regularly-posted newsgroup FAQ was
insufficiently helpful?

I have 2 input fields, startTime, and finishTime.
The times need to be entered like 7:30am or 11:36pm.
Ahh - evidently a Stranger. Those are FFF times; deprecated.

All I want is to subtract the finishTime from the startTime to see how
long something took.
Most people would do the reverse.

I know that this should be real easy,


Correct. It can be done in various ways.

Z = "1970/01/01 " // Should not be a Summer Time Change Date
ST = "7:00am"
FT = "11:36pm"

D = new Date(Z+FT) - new Date(Z+ST)
Ans = new Date(D).toUTCSt ring().replace(/^.* ([^ ]{8}) .*$/, "$1")

-> Ans = "16:36:00" // Assumes that ST <= FT and interval < 24h

I assume that toUTCString uses the 24-h clock in all locations.

If you give only the times, one must ignore source Summer Time changes -
indeed also other time shifts.

To get hh mm ss separately, use D.getUTCHours() etc.

Test in a location where civil time is never GMT or UTC.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3
JRS: In article <Bw************ **@merlyn.demon .co.uk>, dated Mon, 30
Aug 2004 22:44:15, seen in news:comp.lang. javascript, Dr John Stockton
<sp**@merlyn.de mon.co.uk> posted :

D = new Date(Z+FT) - new Date(Z+ST)
Ans = new Date(D).toUTCSt ring().replace(/^.* ([^ ]{8}) .*$/, "$1")


or

D = new Date(Z+FT) - new Date(Z+ST)
Ans = new Date(D).toUTCSt ring().match(/([\d:]{8})/g)

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
Thanks guys!
Jul 23 '05 #5

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

Similar topics

4
4169
by: osmethod | last post by:
Hello, I have read many articles about comparing tables, like - loops, delete queries, appending to temp table with index etc Problem: 2 tables T1 & T2. Data is suppposed to be the same in both tables but i need to check that this is so. (Maybe a user deleted a row in one table only or changed a value in a field!). The tables have no unique index.
1
3466
by: DaveA | last post by:
Our incident numbering system is based on the following YEAR 05 MONTH 06 NMBR 1234 looks like 05-06-1234 the counter number is manually reset each month and I would like to make it automatic. I am having trouble with the comparing the old month stored as two digit number as text with the new two digit month found using format(date(),"mm")
19
2659
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor = Color.Empty then..... or if mycolor is Color.Empty then .......
0
2394
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add D 'Delete
2
1841
by: The guy upstairs | last post by:
Am looking for suggestions on comparing two email fields. Have looked in the usual cut and past sites, but none seem to fit. the name of the two fields are email and confirmEmail. Any suggestions would be appreciated.
21
2345
by: Kristaps | last post by:
Hi everyone! I have some questions, maybe someone can help me... I write script for table comparing, but it works wery slovly. There is the script, can anyone give some tip how can I make this process faster and if it is possible in VB. The idea is to compare two tables and if there is some distinction, then is written in third table. Some tables contains more than 200 000 rows and each row contain approximatelly 30 parameeters (columns)....
2
1790
by: JonoB | last post by:
Need some tips to help me approach this problem. I would consider myself advanced in Access and VBA, so just looking for conceptual pointers. In essence, I have a number of text files, each of which contains data that is parsed into various database tables. The data thus stored in the tables contains 4 fields of information. I have this part of the system working 100%. The 4 fields are: ParseID, lngTime (times are derived in thousands of a...
3
3383
by: Phoe6 | last post by:
I would like to parse RFC 1123 date format and compare two dates. I find that datetime module does not specifically confirms to any RFC. Any suggestions as how I can handle the RFC 1123 date format using standard libraries before I go to re based parsing? Thanks, Senthil
4
6410
by: gillianbrooks91 | last post by:
Forgive me for asking this question, I've trawled through nearly every available post on this subject that I can find for a few weeks now but nothing quite points me in the right direction. I'm quite new to trying to mess around with VB and ADO within MS Access and have realised the steep learning curve I have, but, I want to try and solve this problem quickly and was wondering if anyone would help me out?? I want to be able to...
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.