Jump to content

Date Diffrence between _NowCalc() and FileGettime


great77
 Share

Recommended Posts

; 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?  

Link to comment
Share on other sites

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.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

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

Link to comment
Share on other sites

@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:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

1 minute ago, 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 :)

 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]

 

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

×
×
  • Create New...