Solved

LastModifiedDate compare between 2 files.

Posted on 2001-09-04
12
217 Views
Last Modified: 2008-02-01
Hi, Experts.
I need to compare the last modified date of 2 files (2 same files on different computers).
The problem is on 1 computer the last modified date is 4/9/2001 2:12:24 PM and on the 2 computer this date is 9/4/2001 2:13:15 PM. My program should change the older file with the new one. But on checking the dates it doesn't do it, because it think that the current file is the newer.(The comparing that I do is between two strings.)
I need to check the system identificator of both last modified dates. I need the API function that will convert this date to the Identificator.

Please, I need it ASAP.
Thanks, RRR.
0
Comment
Question by:RRR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
12 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6453335
can you elaborate you question (system identificator)

Anyway you can try to use this api to get file info

Declare Function GetFileTime& Lib "kernel32" (ByVal hFile As Long, _
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As _
FILETIME)


hFile     Long?A handle to a file.
lpCreationTime     FILETIME?A FILETIME structure to load with the creation time of the file.

lpLastAccessTime     FILETIME?A FILETIME structure to load with the last access time of the file (not supported by FAT file systems).

lpLastWriteTime     FILETIME?A FILETIME structure to load with the last modification time of the file.
0
 
LVL 3

Author Comment

by:RRR
ID: 6453374
Hi rkot2000,

The problem is not to get 'Last modified date' attribute of the file, but comparing 2 strings that represent dates
but on 2 different computers with unknown regional date and time settings.
Therefore I need an API function that converts a date to a unique value (Identificator) that can be compared on the remote computer with the remote date unique value.

thaks RRR
0
 

Expert Comment

by:GrahamAtJobserve
ID: 6453443
You dont need an api function.. you just need to do some string manipulation.

Convert the 2 dates into strings of the form yyyymmddhhnnss
and then compare string 1 with string 2. The bigger is the most recent.

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6453461
Try this

Dim fso
    Dim fil1, fil2
   
    Set fso = CreateObject("Scripting.FileSystemObject")
   
    Set fil1 = fso.GetFile("C:\Test1.txt")
    Set fil2 = fso.GetFile("C:\Test2.txt")
   
    Dim dtFile1 As Date
    dim dtFile2 as Date
   
    dtFile1 = fil1.DateLastModified
    dtFile2 = fil2.DateLastModified
   
    Dim lYears As Long
    Dim lMonths As Long
    Dim lDays As Long
    Dim lHours As Long
    Dim lMins As Long
    Dim lSecs As Long
   
    lYears = DateDiff("yyyy", dtFile1, dtFile2)
    lMonths = DateDiff("m", dtFile1, dtFile2)
    lDays = DateDiff("d", dtFile1, dtFile2)
    lHours = DateDiff("h", dtFile1, dtFile2)
    lMins = DateDiff("n", dtFile1, dtFile2)
    lSecs = DateDiff("s", dtFile1, dtFile2)

Vin.
0
 
LVL 3

Author Comment

by:RRR
ID: 6453467
Hi, GrahamAtJobserve.
I had this solution in different way, because your way will do some problems( you can not know where is the day and month of the date). I solved it by using day(mydate) & Month(mydate) & year(mydate) & format(mydate,"HH:NN:SS AMPM") functions.
BUT I would like to know the API function that will return me the unique Identificator of this date.

Thanks, RRR.
0
 

Expert Comment

by:GrahamAtJobserve
ID: 6453469
Using vincents code

if dtFile1 > dtFile2 then
   msgbox "File 1 is most recent"
else
   msgbox "File 2 is most recent"
end if

as dtFile1 and dtFile2 are both dates, you can safely compare them.
0
 
LVL 4

Expert Comment

by:VincentLawlor
ID: 6453508
I was just about to post that as an afterthought

But you get the idea. This should solve your problem for you. Same code as above

    If dtFile1 = dtFile2 Then
        'Files modified at the same time
    ElseIf dtFile1 > dtFile2 Then
        'File1 modified after File2
    ElseIf dtFile1 < dtFile2 Then
        'File2 modified after File1
    End If

You can also use the functions

   dtFile1 = fil1.DateCreated
   dtFile1 = fil1.DateLastAccessed
   
For your comparisons.

Hope that sorts it out.

Vin.
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6453511
How about Coordinated Universal Time(UTC, also known as GMT).

File times returned by this function are UTC.


Type FILETIME  '  8  Bytes
     dwLowDateTime As Long
     dwHighDateTime As Long
End Type

Description

64-bit number specifying the elapsed time since January 1, 1601, in 100-nanosecond increments.

Field     Type/Description
dwLowDateTime, dwHighDateTime     Long?Low and high-order 32 bits of the file time.

Plus you can convert to local time

FileTimeToLocalFileTime

VB Declaration

Declare Function FileTimeToLocalFileTime& Lib "kernel32" (lpFileTime As _
FILETIME, lpLocalFileTime As FILETIME)

Description

Converts a FILETIME structure to local time.

Use with VB

No problem.

Parameter     Type/Description
lpFileTime     FILETIME?Structure containing time in UTC.
lpLocalFileTime     FILETIME?Structure to load with the converted local time.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 300 total points
ID: 6453513
>I had this solution in different way, because your way will do some problems( you can not know where
is the day and month of the date)

Not true, you will only get ambiguity if you use built in date formats such as "short date."  There is no API to get a unique ID from a date, although if you do this:

dim MyDate as Date
MyDate = Now
debug.print cdbl(MyDate)

You will see how date variables are stored internally.
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6453537
>>>Therefore I need an API function that converts a date to a unique value (Identificator) that can be
compared on the remote computer with the remote date unique value.



How about Coordinated Universal Time(UTC, also known as GMT).

File times returned by this function(GetFileTime) are UTC.

Type FILETIME  '  8  Bytes
     dwLowDateTime As Long
     dwHighDateTime As Long
End Type

Description

64-bit number specifying the elapsed time since January 1, 1601, in 100-nanosecond increments.

Field     Type/Description
dwLowDateTime, dwHighDateTime     Long?Low and high-order 32 bits of the file time.

Plus you can convert UTC time to local time :

FileTimeToLocalFileTime

VB Declaration

Declare Function FileTimeToLocalFileTime& Lib "kernel32" (lpFileTime As _
FILETIME, lpLocalFileTime As FILETIME)

Description

Converts a FILETIME structure to local time.

Use with VB

No problem.

Parameter     Type/Description
lpFileTime     FILETIME?Structure containing time in UTC.
lpLocalFileTime     FILETIME?Structure to load with the converted local time.
0
 
LVL 28

Expert Comment

by:Ark
ID: 6455678
Hi
Creating, modifying etc dates store internally in FILE_TIME format (see rkot2000 messages) as LongIntegers (64 bit), not depending to System locale date setting. So, FILE_TIME structure already is "identificator" you're looking for.

To get FileTime structure, you can use GetFileTime API, as rkot2000 showed in his first message.
Then you can compare them:

Declare Function CompareFileTime& Lib "kernel32" (lpFileTime1 As FILETIME, _
lpFileTime2 As FILETIME)

n = CompareFileTime(FT1,FT2)

Return Value

Long?0 if the two times are equal. ?1 if lpFileTime1 is less than lpFileTime2. 1 if lpFileTime1 is more than lpFileTime2.

If you need to convert System Locale Time to "identificator", use

Type SYSTEMTIME  '  16  Bytes
     wYear As Integer
     wMonth As Integer
     wDayOfWeek As Integer
     wDay As Integer
     wHour As Integer
     wMinute As Integer
     wSecond As Integer
     wMilliseconds As Integer
End Type


Declare Function SystemTimeToFileTime& Lib "kernel32" (lpSystemTime As _
SYSTEMTIME, lpFileTime As FILETIME)


Cheers
0
 
LVL 3

Author Comment

by:RRR
ID: 6456087
Hi, All.
I accept the PaulHews's comments as answer, because it is the best solution for me, and it is the simplest and most effective one.

Thanks for all of you,
RRR.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month4 days, 14 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question