Board index » delphi » Convert date to integer?

Convert date to integer?

Hi
I can't figure out how to convert a date to  an  integer i've tried using
DateToInt(Date) but i get 'undeclaired idetifier
any soloutions?
thanks
Alast...@Protimeter.com
 

Re:Convert date to integer?


Quote
"Alastair Dadachanji" <Alast...@Protimeter.com> wrote:
>Hi
>I can't figure out how to convert a date to  an  integer i've tried using
>DateToInt(Date) but i get 'undeclaired idetifier
>any soloutions?
>thanks
>Alast...@Protimeter.com

From the help file...

Unit

System
TDateTime is a used by the date and time routines to hold date and
time values.

type TDateTime = type Double;

Description

Delphi stores date and time values in the TDateTime type. The integral
part of a TDateTime value is the number of days that have passed since
12/30/1899. The fractional part of a TDateTime value is the time of
day.
Following are some examples of TDateTime values and their
corresponding dates and times:
0                  12/30/1899 12:00 am
2.75               1/1/1900 6:00 pm
-1.25              12/29/1899 6:00 am
35065              1/1/1996 12:00 am
To find the fractional number of days between two dates, simply
subtract the two values. Likewise, to increment a date and time value
by a certain fractional number of days, simply add the fractional
number to the date and time value.

Note:   Delphi 1.0 calculated the date from year 1 instead of from
1899. To convert a Delphi 1.0 date to a Delphi 2.0 date, subtract
693594.0 from the Delphi 1.0 date. The date format changed to be more
compatible with OLE 2.0 Automation.

Hope this helps

Joseph

Re:Convert date to integer?


TDateTime is basically 'double', so you should have
no problem using functions like trunc() or similar.

Jozef

Quote
Alastair Dadachanji wrote:

> Hi
> I can't figure out how to convert a date to  an  integer i've tried using
> DateToInt(Date) but i get 'undeclaired idetifier
> any soloutions?
> thanks
> Alast...@Protimeter.com

Re:Convert date to integer?


Alastair,
  TdateTime is a Float, not an integer.This shows the complete date as a
numeric value:

  Showmessage(FloatToStr(now));

if you only want the day portion , use TRUNC on that value.

-Dave

Quote
Alastair Dadachanji wrote:

> Hi
> I can't figure out how to convert a date to  an  integer i've tried using
> DateToInt(Date) but i get 'undeclaired idetifier
> any soloutions?
> thanks
> Alast...@Protimeter.com

--
David G. Parsons
Inprise Certified Delphi 4 Client/Server Developer
Tekmetrics Certified Delphi Programmer
Tekmetrics Certified Visual Basic 5 Programmer
URL: http://www.erols.com/dparsons
Email: dpars...@erols.com
FAX: (603) 947-8207

Re:Convert date to integer?


TDateTime is double (someone said that before? :-)

let's
var
  d: TDateTime

Trunc(d) will return the number of days since 12/30/1899 (negative values also work, since a :=
-1 is date 12/29/1899.
Frac(d) will return a part of a 24 hour day period,
examples:

const
  MsPerDay = 24*60*60*1000; {  86.400.000 }
  Sec = 1.1574074074e-05; { (1*1000) / MsPerDay }

function MSecsElapsed( tm: TDateTime ): integer;
// returns the number of milliseconds elapsed since midnight for a TDateTime
begin
  MSecsElapsed := Trunc(tm*MsPerDay);
end;

function SecToDateTime( seconds: Integer ): TDateTime;
// returns seconds represented as a TDateTime value
begin
  Result := seconds * Sec;
end;

Am I understandable?

Bye,
        Felipe Rocha Machado    
        GPS Tecnologia Ltda.

Quote
Alastair Dadachanji wrote:

> Hi
> I can't figure out how to convert a date to  an  integer i've tried using
> DateToInt(Date) but i get 'undeclaired idetifier
> any soloutions?
> thanks
> Alast...@Protimeter.com

Re:Convert date to integer?


You might want to try the DecodeDate procedure which passes the year, month
and day
as integers.

Quote
Alastair Dadachanji wrote:
> Hi
> I can't figure out how to convert a date to  an  integer i've tried using
> DateToInt(Date) but i get 'undeclaired idetifier
> any soloutions?
> thanks
> Alast...@Protimeter.com

Other Threads