Jump to content

Compare File Modified Date to Current System Time


Recommended Posts

I've looked thru the forums and found lots of examples with file dates but not comparing a filedate to the system date.

Dates are very funny with all the weird formatting and I can't seem to find a way to do it! I'm looking for how many hours old the file is.

Can someone give me a hand please!

Func FileHowOldHours( $cFile )
 
Local $TempFileDate = FileGetTime( $cFile , 0 )
Local $Date = @MON & "/" & @MDAY & "/" & @YEAR
Local $JobLastRun = $TempFileDate[1] & "/" & $TempFileDate[2] & "/" & $TempFileDate[0]
 
Return  _DateDiff("h", $JobLastRun, $Date)
EndFunc
Edited by Patchworks
Link to comment
Share on other sites

You weren't including the time in the $Date variable. Look at this code, modify it to your needs. Note that I used 's' (seconds) in the _DateDiff function, that was just for my testing.

#include <Date.au3>
Local $TempFileDate = FileGetTime( @ScriptName, 0 )
Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5]

MsgBox(0, '', _NowCalc() & @CRLF & $JobLastRun & @CRLF & _DateDiff("s", $JobLastRun, _NowCalc()))

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

You weren't including the time in the $Date variable. Look at this code, modify it to your needs. Note that I used 's' (seconds) in the _DateDiff function, that was just for my testing.

#include <Date.au3>
Local $TempFileDate = FileGetTime( @ScriptName, 0 )
Local $JobLastRun = $TempFileDate[0] & "/" & $TempFileDate[1] & "/" & $TempFileDate[2] & " " & $TempFileDate[3] & ":" & $TempFileDate[4] & ":" & $TempFileDate[5]
 
MsgBox(0, '', _NowCalc() & @CRLF & $JobLastRun & @CRLF & _DateDiff("s", $JobLastRun, _NowCalc()))

Thanks bud, you help was crutial. Here is what I ended up with.

Func LogFileAgeInHours( $cLogFile )
Local $cFileDate = FileGetTime( $cLogFile , 0 )  ;Get the Last Modified date and time
Return _DateDiff("h", $cFileDate[0] & "/" & $cFileDate[1] & "/" & $cFileDate[2] & " " & $cFileDate[3] & ":" & $cFileDate[4] & ":" & $cFileDate[5] , _NowCalc())
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...