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


LVL 1
hidrauAsked:
Who is Participating?
 
Vee_ModConnect With a Mentor Commented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0
 
MerijnBSr. Software EngineerCommented:
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.
0
 
LimbeckCommented:
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;
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
multithreadingCommented:
It's easy: int comparison = dateTimeA.CompareTo(dateTimeB);
0
 
hidrauAuthor Commented:
I found a function that gives me what I need

  DateTimeToUnix()

and

  UnixToDateTime()
0
 
mikelittlewoodCommented:
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.
0
 
ziolkoCommented:
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.
0
 
diniludCommented:
is this function is OK?

DateTimeToFileDate()
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.