[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9778
  • Last Modified:

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


0
hidrau
Asked:
hidrau
1 Solution
 
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
 
multithreadingCommented:
It's easy: int comparison = dateTimeA.CompareTo(dateTimeB);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
Vee_ModCommented:
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now