Sign in to follow this  
Followers 0
Patchworks

Compare File Modified Date to Current System Time

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Ok, 2nd attempt here!!!

Func LogFileAgeInHours( $cLogFile )
Local $cFileDate = FileGetTime( $cLogFile , 0 )
Return _DateDiff("h", $cFileDate , _NowDate())
EndFunc

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Glad I could help. Good luck with the rest of your project.


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

Share this post


Link to post
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
Sign in to follow this  
Followers 0