C++'s DateTime.Now.Ticks.ToString() Equivalent in delphi?

DateTime.Now.Ticks.ToString() in C++ what is the equivalent in delphi? The strings generated seem very different because I don't think GetTickCount() is the same.. thanks

string hash_id = Utilities.GetMd5Hash(DateTime.Now.Ticks.ToString());
hash_id = hash_id.Substring(0,8)  + "-" + hash_id.Substring(8, 4) + "-" + hash_id.Substring(12, 4) + "-" + hash_id.Substring(16, 4) + "-" + hash_id.Substring(20, 12);

Open in new window


my code:
function sessionhash:string;
var
h,b:string;
begin
h := lowercase(md5string(DateToStr(GetTickCount())));
b := copy(h,0,8)+'-'+copy(h,8,4)+'-'+copy(h,12,4)+'-'+copy(h,16,4)+'-'+copy(h,20,12);
result := b;
end;

Open in new window

nickdelphi777Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
As per the MSDN you get the Difference from 1-Jan-0001 12:00:00 midnight, and not the CPU TickCount.

The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue. It does not include the number of ticks that are attributable to leap seconds.

If I understood the MSDN correctly, the following code is the equivalent of "DateTime.Now.Ticks":
uses DateUtils;

function sessionhash:string;
var
  dt:TDateTime;
  h, b, tick_str:string;
begin
  dt:= EncodeDate(1,1,1);  //1-Jan-0001
  dt:= EncodeTime(0,0,0,0); //12:00:00 midnight
  tick_str:= inttostr(round((MilliSecondsBetween(now,dt) * 1000000) / 100));  //100-nanosecond intervals that have elapsed, 1 m.s. = 1000000 n.s.
  h := lowercase(md5string(tick_str));
  b := copy(h,0,8)+'-'+copy(h,8,4)+'-'+copy(h,12,4)+'-'+copy(h,16,4)+'-'+copy(h,20,12);
  result := b;
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sinisa VukSoftware architectCommented:
Think that Environment.TickCount is equal to Delphi's GetTickCount (32 bit)
system.environment.tickcount
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.