Solved

# datetime to integer

Posted on 2007-08-08
9,092 Views
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

0
Question by:hidrau

LVL 19

Expert Comment

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

LVL 19

Expert Comment

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

LVL 7

Expert Comment

It's easy: int comparison = dateTimeA.CompareTo(dateTimeB);
0

LVL 1

Author Comment

I found a function that gives me what I need

DateTimeToUnix()

and

UnixToDateTime()
0

LVL 15

Expert Comment

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

LVL 21

Expert Comment

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:

ziolko.
0

LVL 10

Expert Comment

is this function is OK?

DateTimeToFileDate()
0

LVL 1

Accepted Solution

Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

## Featured Post

### Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!