Jump to content

Recommended Posts

Posted
; put the root in a variable
$sRoot = "C:\Project\PHexample\"

Global $sCurrentTime = _NowCalc()

; We can use that variable here
Global $aList = _FileListToArray($sRoot, Default, 2)
If @error Then Exit ;;;;;;MsgBox(0, "Error", "_FileListToArray returned @error = " & @error)

;;;;;;;;;;;This is a loop that runs from 1 to the number of items listed in the first element of the returned  array
For $i = 1 To UBound($aList) - 1
    

MsgBox(0, "Folder date", $sRoot & "" & $aList[$i] & @CRLF & @CRLF & FileGetTime($sRoot & "" & $aList[$i], 1, 1))

    MsgBox(0, "Folder date", FileGetTime($sRoot & "" & $aList[$i], 1, 1))

     $a_filenew = StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), ":", ""), " ", "")
      MsgBox(0, "Folder date", $a_filenew)
$adex =  _DateDiff('D', FileGetTime($sRoot & "" & $aList[$i], 1, 1), $a_filenew)

 MsgBox(0,"ade", $adex)

Next

I have a code as seen above, but the difference in time is returning zero. I understand that the date yyyymmddhhmmss but how can I find the difference.

The purpose is to try find the difference in days. Any suggestion?  

Posted

Have you compared your values to the values in the Help file example?

https://www.autoitscript.com/autoit3/docs/libfunctions/_DateDiff.htm

As a clue, please note that _NowCalc() is used as is, not modified like you have done.

_DateDiff requires date+time to be in the correct format, space and all.

 

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

  Reveal hidden contents

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

@great77

Look closely in the Help file about _DateDiff()! :)
Try this:

Global $strFileName = @ScriptDir & "\File.txt", _
       $arrFileTime, _
       $strFileTime = "", _
       $strNowCalc = "", _
       $strDateDiff = ""

; Get the Date/Time for the Created property of the file
$arrFileTime = FileGetTime($strFileName, $FT_CREATED, $FT_ARRAY)

; Format the Date/Time to calculate the difference
$strFileTime = $arrFileTime[0] & "/" & $arrFileTime[1] & "/" & $arrFileTime[2] & " " & $arrFileTime[3] & ":" & $arrFileTime[4] & ":" & $arrFileTime[5]

; Get the "Now" time to calculate the difference
$strNowCalc = _NowCalc()

; Calculate the difference in Days ("D")
$strDateDiff = _DateDiff("D", $strFileTime, $strNowCalc)

; Display the Difference in Days
ConsoleWrite("Difference between '" & $strFileTime & "' and '" & $strNowCalc & "' ( in Days ) = " & $strDateDiff & @CRLF)

Cheers :)

Edited by FrancescoDiMuro

Click here to see my signature:

  Reveal hidden contents

 

Posted
  On 9/11/2018 at 8:52 AM, FrancescoDiMuro said:

@great77

Look closely in the Help file about _DateDiff()! :)
Try this:

Global $strFileName = @ScriptDir & "\File.txt", _
       $arrFileTime, _
       $strFileTime = "", _
       $strNowCalc = "", _
       $strDateDiff = ""

; Get the Date/Time for the Created property of the file
$arrFileTime = FileGetTime($strFileName, $FT_CREATED, $FT_ARRAY)

; Format the Date/Time to calculate the difference
$strFileTime = $arrFileTime[0] & "/" & $arrFileTime[1] & "/" & $arrFileTime[2] & " " & $arrFileTime[3] & ":" & $arrFileTime[4] & ":" & $arrFileTime[5]

; Get the "Now" time to calculate the difference
$strNowCalc = _NowCalc()

; Calculate the difference in Days ("D")
$strDateDiff = _DateDiff("D", $strFileTime, $strNowCalc)

; Display the Difference in Days
ConsoleWrite("Difference from '" & $strFileTime & "' and '" & $strNowCalc & "' ( in Days ) = " & $strDateDiff & @CRLF)

Cheers :)

Expand  

 Thanks so much . This is what am looking for was trying to format the FileGetime but do not know that this bit below is the solution

$arrFileTime = FileGetTime($strFileName, 1, 0)  ;;
$strFileTime = $arrFileTime[0] & "/" & $arrFileTime[1] & "/" & $arrFileTime[2] & " " & $arrFileTime[3] & ":" & $arrFileTime[4] & ":" & $arrFileTime[5]

 

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
×
×
  • Create New...