Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check time between two TDateTimes

Posted on 1998-07-19
6
Medium Priority
?
291 Views
Last Modified: 2010-08-05
OK, I've started making a simple alarm program and I've run into a fairly major problem - I'm saving all my alarms OK and successfully recalling them as TDateTimes, but there's a difficulty.  Are you sitting comfortably?

Say I have alarms at 08:30, 11:15 and 16:30.  This is fine if the app starts before the earliest alarm - it can progress through the sequence easily enough.  But since the app runs on a network, it is getting started and stopped all the time, so if a user logs on and the app runs at 10:13, it needs to reorganize the order in which the alarms come.

Bear in mind that this has to be flexible: a user might stay logged on for over 24 hours...

I've tried doing stuff like Now-AlarmOne but mathematical operators seem to go haywire with this!

Good Luck!

Ed
0
Comment
Question by:edmoore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1358201
The TDateTime format allows you to compare times. You can write a thing like this: if time1> time2 then... Do you understand? It will compare the first time and the seccond.

Can you exaplin better what is your problem and what you don't understand?
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1358202
Most mathematical operators should work fine with TDateTime.

The most commonly used is -
But you can also / * and + with it.

(Time2-Time1)*24*60 is the amount of minutes passed between Time1 and Time2.

A TDateTime is just a Double.

The whole part are the days since 1899.
The fraction is the part of the day.

1.5 =

1 day
12 hours

1 hour is 1/24
1 minute 1/(24*60)
1 second 1/(24*60*60)

You can also use DecodeDate EncodeDate DecodeTime and EncodeTime.

Regards Jacco
0
 

Expert Comment

by:nileq
ID: 1358203
Could you define your problem more?
Lets say a user logs on at 10:13, he had an alarm set at 08:30 do you wont that alarm to go off?
Should the 08:30 alarm go off every day or only on the set date?

Let me know and I will help you.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:ZifNab
ID: 1358204
? Time and date are stored in a float type (or is it double?). Heck doesn't mind, either way the date is defined with the numbers before the decimal separator and time is defined with these after the decimal sperator. Now when you compare two times it is fairly simple isn't it? the number later on the day will always be greater then the other....

Or am I missing the question here?

Zif.
0
 
LVL 6

Accepted Solution

by:
Holger101497 earned 280 total points
ID: 1358205
ok, several people so far have said that the date is in the integer part and the time in the frac-part.
The reason I'm posting this as an answer is because I think I see your problem: These are DAILY alarms, right? 8:30 every day?
You can "solve" your problems by using the frac-part of your times, thereby ignoring the date/day.

IF (Frac(Now)>Frac(Alarm)) // later than alarm
AND (Frac(Now)<Frac(Alarm)+5/24/60) //alarm time less than 5 minutes ago
THEN SoundAlarm;
// btw: "now" is a function - instead of calling it several times, store result in a variable. Also reduces strange effects if "Now" changes from line to line *g* - it rarely hits a critical value, but if it only happens once in a thousand times, it's almost impossible to track down :-))

Of course you have to "remember"/store which alarms were used and which ones weren't...

I don't really see a need to "sort" the alarms, but if you really want to:
SecsRemaining:=Round( (Frac(Alarm)-Frac(Now)+1)*24*60*60) MOD (24*60*60);
// if you are using 16-bit Delphi, you might need to typecast to avoid overflows
// this should return the seconds remaining before the alarm should be triggered the next time. Use this value to sort.


Good luck! Let me know if that helped and ask for details before rejecting the answer.
:o))

It's ( '-)
:-))
0
 

Author Comment

by:edmoore
ID: 1358206
OK, thanks everyone for helping me with this - I didn't realise how quickly it would fill up or I would have checked back more often.

I'll have to award the points to the only actual formal answer, but all of you have been very helpful, thanks!

Ed :)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question