Link to home
Start Free TrialLog in
Avatar of hidrau
hidrauFlag for Brazil

asked on

datetime to integer

Hello guys,

I have a date and time variable and I would like to transform it in an integer value so that I can use
the value to compares,

Example:

10/08/2007 10:45
10/08/2007 10:47
10/08/2007 10:58
10/08/2007 10:15


Avatar of MerijnB
MerijnB
Flag of Netherlands image

what do you want to compare?
You do not need to convert it to an integer (which isn't even possible, only to float) to compare.
Avatar of Limbeck
Limbeck

you can adress a tdatetime as a double :) why would you need an integer?

and use them to compare in what way? is it a string or a tdatetime var?if it is a string you can use Strtodatetime

fi

var a:tdatetime;

begin
  a:=Strtodatetime('10/08/2007 10:45');
end;
It's easy: int comparison = dateTimeA.CompareTo(dateTimeB);
Avatar of hidrau

ASKER

I found a function that gives me what I need

  DateTimeToUnix()

and

  UnixToDateTime()
Can you not use the standard

CompareDateTime( dateTime1, dateTime2)

Which will return -1, 0 or +1 depending which is larger or if they are equal.
system.pas defines
TDateTime = type Double;

so you can compare dates using standard operators (=, <, >) or as mike suggested use CompareDateTime (defined in DateUtils.pas).

if you really, really, really need integer use:
datetime_as_int := Round(ADateTime * SecsPerDay)

ziolko.
is this function is OK?

DateTimeToFileDate()
ASKER CERTIFIED SOLUTION
Avatar of Vee_Mod
Vee_Mod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial