Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date functions in Delphi

Status
Not open for further replies.

davidrobin

Programmer
Aug 17, 2000
50
GB
I am a VB6 user where there are plenty of date functions for all different uses
e.g.
DateDiff() Difference between 2 dates
DateAdd()
Year()
Month()
etc

I looked in the help system and there appears to be no date functions. I find this hard to believe. Can anyone throw any light on the subject.
David
Visual Basic 6 Ent
 
In Delphi there are also many Date functions. Most of them you can find in help searching "DateTo..." for conversion from date to something. These functions also have their opposites. To extract year, month and day from the date use DecodeDate() function. For other functions look in Delphi Help.
 
Type somewhere on the form tdatetime, highlight it and press F1, this will bring up help for the tdatetime datatype, click on see also, and you have the list of all date en time related functions and procedures in Delphi. I counted 86.

The same method can be used for any reserved word in delphi.

Regards Steven van Els
SAvanEls@cq-link.sr
 
David,

If you're using either the Professional or Enterprise editions of Delphi and have installed the RTL source, you can also read source of the SYSUTILS.PAS unit, which implements a number of date/time related functions and is (in version 6) pretty heavily documented.

If you're not sure where to find SYSUTILS:

1. Make an editor window active
2. Type sysutils and then right-click it.
3. Choose Open File at Cursor from the shortcut menu.

SYSUTILS is a pretty beefy unit, so you might need to scroll down to locate the date/time stuff. But, there's a lot of good info.

(BTW, the source and demo files provided with Delphi can be excellent sources of information, examples, and hidden gems.)

Hope this helps...

-- Lance
 
Is there a function that returns how many seconds between two dates. David
Visual Basic 6 Ent
 
If one makes(does) the difference between 2 dates, one obtains a result of the real type which represents the day number among that this. If this result is multiplied by 24*60*60, we obtain the difference in second.

var
date1,date2:tdatetime;
sec:float;
begin
...
sec:=(date2-date1)*24*60*60;
...
end;

Laurent

;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top