Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:13:07+00:00 2026-05-16T10:13:07+00:00

I have a utility that compares a source and destination file date/time. This works

  • 0

I have a utility that compares a source and destination file date/time. This works in most cases but fails when comparing date/time for files in different time zones. So I need a UTC datetime routine.

From looking around it seems the Windows API GetFileTime will support this. I also found this wrapper procedure, but it crashes on the GetFileTime call when compiled under Delphi 2010.

Any ideas? Or does anyone have a snippet of code that handles UTC timezones etc that I can pass 2 filenames to that will tell me if they are different?

function CompareFileTimes(File1, File2 : String) : LongInt;
var
  F1, F2          : THandle;
  F1_CreateTime,
  F1_LastAccess,
  F1_LastWrite,
  F2_CreateTime,
  F2_LastAccess,
  F2_LastWrite    : PFileTime;
begin
  //Initialize all variables
  F1 := 0;
  F2 := 0;

  //Since these are pointers, we have to
  //allocate memory for the FileTime structures
  GetMem(F1_CreateTime, SizeOf(TFileTime));
  GetMem(F1_LastAccess, SizeOf(TFileTime));
  GetMem(F1_LastWrite, SizeOf(TFileTime));
  GetMem(F2_CreateTime, SizeOf(TFileTime));
  GetMem(F2_LastAccess, SizeOf(TFileTime));
  GetMem(F2_LastWrite, SizeOf(TFileTime));

  //Fill the structures with nulls for now
  FillChar(F1_CreateTime, SizeOf(TFileTime), #0);
  FillChar(F1_LastAccess, SizeOf(TFileTime), #0);
  FillChar(F1_LastWrite, SizeOf(TFileTime), #0);
  FillChar(F2_CreateTime, SizeOf(TFileTime), #0);
  FillChar(F2_LastAccess, SizeOf(TFileTime), #0);
  FillChar(F2_LastWrite, SizeOf(TFileTime), #0);

  //Get file handles for the files in question
  //Notice that even though we're using CreateFile
  //the open disposition for the file is OPEN_EXISTING
  F1 := CreateFile(PChar(F1), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  F2 := CreateFile(PChar(F2), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  //Get the file times for the files.
  GetFileTime(F1, F1_CreateTime, F1_LastAccess, F1_LastWrite);
  GetFileTime(F2, F2_CreateTime, F2_LastAccess, F2_LastWrite);

  //Assign the function's result to comparison
  //-1, File1 is younger than File2
  //0, File1 is the same as File2
  //+1 File1 is older than File2
  Result := CompareFileTime(F1_CreateTime^, F2_CreateTime^);

  //Free the memory allocated to the pointers
  FreeMem(F1_CreateTime, SizeOf(TFileTime));
  FreeMem(F1_LastAccess, SizeOf(TFileTime));
  FreeMem(F1_LastWrite, SizeOf(TFileTime));
  FreeMem(F2_CreateTime, SizeOf(TFileTime));
  FreeMem(F2_LastAccess, SizeOf(TFileTime));
  FreeMem(F2_LastWrite, SizeOf(TFileTime));
end;

Any help will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:13:07+00:00Added an answer on May 16, 2026 at 10:13 am

    Delphi 2010 already contains an easy wrapper for getting the UTC time in ioutils.pas. Here is a piece of code that compares UTC creation times of files.

    uses
      IOUtils, DateUtils;
    
    function CompareFileCreationTimeUtc(const aFile1, aFile2: String): integer;
    var
      lCreationTime1: TDateTime;
      lCreationTime2: TDateTime;
    begin
    
      lCreationTime1 := TFile.GetCreationTimeUtc(aFile1);
      lCreationTime2 := TFile.GetCreationTimeUtc(aFile2);
    
      Result := CompareDateTime(lCreationTime1, lCreationTime2);
    
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.