473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rolling back 24 hour times

As part of an assignment I need to calculate a 24 hour time by subtracting a
one time from another e.g. if the user enters 1.00 as the time and 1.30 as
the time to subtract the returned time is 23.30 the previous day.

This is straightforward when dealing with positive times. But when negative
times are introduced (as above) it all gets tricky.

I'd originally thought that a lookup table of times against a corresponding
negative time might be useful. But this wouldn't be flexible enough to
handle anything later than 24 hours.

Is there a mathematical way to calculate this? I don't want the code written
for me, just a few ideas.

TIA
Nov 13 '05 #1
5 2018
On Wed, 12 Nov 2003 08:48:14 +0000, marty wrote:
Is there a mathematical way to calculate this? I don't want the code written
for me, just a few ideas.


Look at the modulo operator (%) in your textbook.

--
NPV

"the large print giveth, and the small print taketh away"
Tom Waits - Step right up

Nov 13 '05 #2
"marty" <rmartin@n^t^l^ w^o^r^l^d^.^c^o ^m^> wrote:
As part of an assignment I need to calculate a 24 hour time by
subtracting a one time from another e.g. if the user enters 1.00
as the time and 1.30 as the time to subtract the returned time
is 23.30 the previous day. [snip] Is there a mathematical way to calculate this? I don't want the
code written for me, just a few ideas.


You can regard both the time and the offset as an integer number of
minutes before or after midnight, and just add the two integers.

Then normalise the result into hours and minutes (first adding 24 hours
to cancel out any negative values).

Brought to you by the numbers 60 and 1440, and the operators +, *, /
and especially %.

--
Simon.
Nov 13 '05 #3


marty wrote:
As part of an assignment I need to calculate a 24 hour time by subtracting a
one time from another e.g. if the user enters 1.00 as the time and 1.30 as
the time to subtract the returned time is 23.30 the previous day.

This is straightforward when dealing with positive times. But when negative
times are introduced (as above) it all gets tricky.

I'd originally thought that a lookup table of times against a corresponding
negative time might be useful. But this wouldn't be flexible enough to
handle anything later than 24 hours.

Is there a mathematical way to calculate this? I don't want the code written
for me, just a few ideas.


You might be able to substract or add to bring the values in range.

double time = 1.00; /* represents 1 am */

time-=50.50; /* substact 50.5 hours */
while(time < 24.0) time+=24.0;
while(time > 24.0) time -=24.0;

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 13 '05 #4

"Al Bowers" <xa******@rapid sys.com> wrote in message
news:bo******** *****@ID-169908.news.uni-berlin.de...


marty wrote:
As part of an assignment I need to calculate a 24 hour time by subtracting a one time from another e.g. if the user enters 1.00 as the time and 1.30 as the time to subtract the returned time is 23.30 the previous day.

This is straightforward when dealing with positive times. But when negative times are introduced (as above) it all gets tricky.

I'd originally thought that a lookup table of times against a corresponding negative time might be useful. But this wouldn't be flexible enough to
handle anything later than 24 hours.

Is there a mathematical way to calculate this? I don't want the code written for me, just a few ideas.


You might be able to substract or add to bring the values in range.

double time = 1.00; /* represents 1 am */

time-=50.50; /* substact 50.5 hours */
while(time < 24.0) time+=24.0;
while(time > 24.0) time -=24.0;

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/


That was very useful, thanks all.
Nov 13 '05 #5
Al Bowers wrote:

marty wrote:
As part of an assignment I need to calculate a 24 hour time by subtracting a
one time from another e.g. if the user enters 1.00 as the time and 1.30 as
the time to subtract the returned time is 23.30 the previous day.

This is straightforward when dealing with positive times. But when negative
times are introduced (as above) it all gets tricky.

I'd originally thought that a lookup table of times against a corresponding
negative time might be useful. But this wouldn't be flexible enough to
handle anything later than 24 hours.

Is there a mathematical way to calculate this? I don't want the code written
for me, just a few ideas.


You might be able to substract or add to bring the values in range.

double time = 1.00; /* represents 1 am */

time-=50.50; /* substact 50.5 hours */
while(time < 24.0) time+=24.0;
while(time > 24.0) time -=24.0;


The fmod() function might be convenient here.

Also, note that simple arithmetic will not always
yield the correct result, because not all days are 24.0
hours long. Many parts of the world observe a seasonal
variation involving one 23-hour and one 25-hour day per
year, and *all* of the world (except the POSIX committee,
I've heard) admits the introduction or deletion of leap
seconds twice yearly.

--
Er*********@sun .com
Nov 13 '05 #6

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

Similar topics

9
1721
by: Marcus | last post by:
Hello, Say I have a function with 5 MySQL queries that all insert or update the database. Now let's assume that during execution, the first 3 queries are executed fine but then the 4th one dies for some reason - problem with the database, connection, whatever. Obviously I can test the $result variable to see if it returns true or false, but given the case above, the database is now left in a "corrupt" state (assuming all 5 queries...
0
1328
by: M Wells | last post by:
Hi All, I don't know if this is a truly esoteric question, or not, but I'm wondering how (or even if) you handle a timeout on a transaction within a stored procedure executed in a Stored Procedure? A theoretical example of the stored procedure (sadly, I'm not allowed to post the actual code):
1
4679
by: Andy Hall | last post by:
Hi, I am rolling back a transaction that (up to the rollback command) has inserted into two tables, both of which are type InnoDB. I am getting the warning: "Warning: Some non-transactional changed tables couldn't be rolled back" I check the database and it seems to have rolled back all the changes I expected it to make, so why is this error occurring. I am using MySQL
5
2399
by: Tom wilson | last post by:
I'm developing an application that is a benefits enrolment website. The benefits can be of any type in any order as stored in a SQL server. On each page is a Back and Next button. At a certain point in the initialization of the app, I determine a navigational structure; what benefit is first, second, etc., therefore, which page to display first, second and so on. In session memory I store an array of page URL's and a single value...
1
2191
by: mike | last post by:
Is it possible to undo a transaction after it has completed (using 8 beta1) ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings
1
3517
by: cricketweb | last post by:
I have a stored procedure that calls another stored procedure with the first stored procedure opening a transaction: BEGIN SET XACT_ABORT ON BEGIN TRANSACTION does various updates/inserts
4
1932
by: brendan.wong | last post by:
hello. i'm trying to incorporate error handling into my application, but i've run into a dilemma. i've already performed 10 successful INSERTS, but on the 11th INSERT, the application fails for some reason (say for example, i tried to perform an INSERT into a table that doesn't exist). logically, i should stop execution and display some sort of error message. but, i've already ran a bunch of INSERTS so what do i do? thanks
8
1758
by: valentin tihomirov | last post by:
Once file is open, it should be closed: Stream fs = new FileStream(filename, FileMode.Create); try { // write, exceptions may raise here } finally { fs.Close(); }
1
1699
by: sreemati | last post by:
Hi Everyone, In brief, I am trying to get the whole block of code done in one go or not to do at all. Here is a piece of code I am trying: BEGIN TRANSACTION INSERT INTO authors (au_id, au_lname, au_fname, phone, contract) VALUES ('172-32-1176', 'Mickey', 'Mouse', '222-33-4444', 1)
0
9621
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
9454
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
8937
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
7461
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...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
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.