Solved

easy question on handling date/time

Posted on 2001-06-20
7
214 Views
Last Modified: 2010-04-04
hi!

is there any procedure/function in delphi which returns the seconds after a specific time? (e.g. how many seconds are between 01.01.1990, 12:00:00 and today?)

I need to compare to dates/time to get the result how many seconds are between two times/dates.

For example i want to know how long it is in seconds between 01.01.01 12:00:00 and 01.01.2001 12:01:38. the problem is how to handle the midnight when the date changes.

thx for your answers

martin
0
Comment
Question by:martinpauly
7 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6209723
Hi martinpauly,

use TDateTime. It  is just floating number. Ceil part - days, frac part is part of day.
0.5 - is 12 hours
0.25 - 6 hours
so you can substract two dates and it's time
  D := D2 - D1;
and then convert it into seconds
  SEC := Round(D*24*60*60);

----
Igor.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6209747
Hello,

ITugay is right ;-)

you can use this function:

Function SecBetween(Date1,Date2:tDateTime):Integer;
begin
  Result := trunc(date1-date2)*24*3600
end;

Best Regards

Cesario
0
 

Author Comment

by:martinpauly
ID: 6211051
hi,

the solution you wrote doesn't work. The Result of
date1 - date2 is always 0. So the multiplication with 24 and 3600 doesn't work. to set date1 and date2 i use:

date1:=strtodatetime('01.02.01 23:59:00');
date2:=strtodatetime('01.03.01 00:01:00');
(german date and time settings)

any ideas what i can do?

greetings martin
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 4

Expert Comment

by:StevenB
ID: 6212555
 Are you sure that you've declared date1 and date2 as TDateTime, not TDate? The function supplied by Cesario should work in this case.
0
 
LVL 3

Accepted Solution

by:
f15iaf earned 50 total points
ID: 6212562
sect is the number of seconds beetwen 2 dates

var
        date1,date2:Tdatetime;
        tm,tm1:Ttimestamp;
        sect:cardinal;
begin
        date1:=strtodatetime('01.02.01 23:59:00');
        date2:=strtodatetime('01.03.01 00:01:00');
        tm:=datetimetotimestamp(date1);
        tm1:=datetimetotimestamp(date2);
        sect:=(tm1.Date-tm.Date)*86400+(tm1.time-tm.Time) div 1000;
end;
0
 
LVL 4

Expert Comment

by:DMN
ID: 6212573
Or:

Result := (Date2-Date1)*86400;

If you wish integer number of seconds:

Result := Round((Date2-Date1)*86400);
0
 

Author Comment

by:martinpauly
ID: 6214366
to stevenB: yes i'm sure i use tdatetime to declare

to  DMN: your solution doesn't work! same problem i wrote above.

to f15iaf : your right! thx a lo
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now