Jump to content

Can't compare dates


 Share

Recommended Posts

I'm trying to find the months between 2 dates. 1 date from a folder and the current date.

If I do exampel 1 it works

Local $iDateCalc = _DateDiff('M', "2015/10/23 00:00:00", _NowCalc())
MsgBox($MB_SYSTEMMODAL, "", "Number of: " & $iDateCalc)

but exampel 2 do not.

Local $aFileDate = FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName)
Local $iDateCalc = _DateDiff('M', $aFileDate[0] & "/" &  $aFileDate[1] & "/" & $aFileDate[2] & " 00:00:00", _NowCalc())
MsgBox($MB_SYSTEMMODAL, "", $iDateCalc)

 

 Can someone help me?
 

Yours sincerely

Kenneth.

Link to comment
Share on other sites

  • Developers

FileGetTime() returns an Array by default. Look at the helpfile for defining the return of a string with the optional second parameter.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Tried that too.

Local $sFileDate = _ConvertTimeFormat(FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName,0,1))
MsgBox($MB_SYSTEMMODAL, "", $sFileDate)
Local $iDateCalc = _DateDiff('M', $sFileDate, _NowCalc())
MsgBox($MB_SYSTEMMODAL, "", $iDateCalc)


Func _ConvertTimeFormat ( $_FileTime ) ; convert 20100716213616 string time format to this time format YYYY/MM/DD HH:MM:SS
    Return StringMid ( $_FileTime, 1 , 4 ) & '/' & StringMid ( $_FileTime, 5 , 2 ) & '/' & StringMid ( $_FileTime, 7 , 2 ) & _
    ' ' & StringMid ( $_FileTime, 9 , 2 ) & ':' & StringMid ( $_FileTime, 11 , 2 ) & ':' & StringMid ( $_FileTime, 13 , 2 )
EndFunc ;==> _ConvertTimeFormat ( )

Same result.

Result = 0

Yours sincerely

Kenneth.

Link to comment
Share on other sites

Are you sure your filepath is correct? Because this:

; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>

$sFileDate=_ConvertTimeFormat(FileGetTime(@AutoItExe,1,1))
ConsoleWrite($sFileDate&@CRLF)
Local $iDateCalc = _DateDiff('M', $sFileDate, _NowCalc())
MsgBox($MB_SYSTEMMODAL, "", $iDateCalc)



Func _ConvertTimeFormat ( $_FileTime ) ; convert 20100716213616 string time format to this time format YYYY/MM/DD HH:MM:SS
    Return StringMid ( $_FileTime, 1 , 4 ) & '/' & StringMid ( $_FileTime, 5 , 2 ) & '/' & StringMid ( $_FileTime, 7 , 2 ) & _
    ' ' & StringMid ( $_FileTime, 9 , 2 ) & ':' & StringMid ( $_FileTime, 11 , 2 ) & ':' & StringMid ( $_FileTime, 13 , 2 )
EndFunc ;==> _ConvertTimeFormat ( )

works for me.

Link to comment
Share on other sites

When I run your small example I get 4 in the msgbox, but nothing in the console.

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\yt\test.au3" /UserParams   
+>19:54:12 Starting AutoIt3Wrapper v.15.920.938.0 SciTE v.3.6.0.0   Keyboard:00000406  OS:WIN_10/  CPU:X64 OS:X64    Environment(Language:0809)
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\MyName\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\DKSOKVK\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\yt\test.au3
+>19:54:12 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\yt\test.au3"   
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
2015/09/18 15:13:00
 

This is what I try:

For $i = 0 To UBound($aUsersTarget) - 1
    $aComputerOwner = _AD_GetObjectsInOU("OU=computers," & $sSiteOU & ",OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=computer)(managedby=" & $aUsersTarget[$i][0] & "))",Default,"cn")
    if $aComputerOwner <> 0 Then
        Local $hSearch = FileFindFirstFile($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & "*.")
        If $hSearch = -1 Then
;           MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
        EndIf
        Local $sFileName = ""
        While 1
            $sFileName = FileFindNextFile($hSearch)
            ; If there is no more file matching the search.
            If @error Then ExitLoop
            if UBound(_ArrayFindAll($aComputerOwner,$sFileName)) = 0 Then
                if StringInStr($sFileName,StringUpper(stringRight($sSiteOU,2) & StringMid($sSiteOU,StringInStr($sSiteOU,",")-2,2)&"LT")) <> 0 Or StringInStr($sFileName,StringUpper(stringRight($sSiteOU,2) & StringMid($sSiteOU,StringInStr($sSiteOU,",")-2,2)&"DT")) <> 0 Then
                    Local $sFileDate = _ConvertTimeFormat(FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName,0,1))
                    Local $iDateCalc = _DateDiff('M', $sFileDate, _NowCalc())
                    MsgBox($MB_SYSTEMMODAL, "", $iDateCalc) ; <--- Not the result I expected
                EndIf
            EndIf
        WEnd
        ; Close the search handle.
        FileClose($hSearch)
    EndIf
Next

 

The attachment is for showing the data before and after use of _ConvertTimeFormat and current date and time.

MsgBox($MB_SYSTEMMODAL, "", FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName,0,1)&@CRLF&$sFileDate&@CRLF&_NowCalc())

 

FileGetTime.JPG

Edited by Valnurat

Yours sincerely

Kenneth.

Link to comment
Share on other sites

When i change my testscript to

; *** Start added by AutoIt3Wrapper ***
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>

$sFileDate='20151127092237'
;$sFileDate=FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName,0,1)
;$sFileDate=FileGetTime(@AutoItExe,1,1)
$sFileDate=_ConvertTimeFormat($sFileDate)
ConsoleWrite($sFileDate&@CRLF)
Local $iDateCalc = _DateDiff('M', $sFileDate, _NowCalc())
MsgBox($MB_SYSTEMMODAL, "_DateDiff", $iDateCalc)



Func _ConvertTimeFormat ( $_FileTime ) ; convert 20100716213616 string time format to this time format YYYY/MM/DD HH:MM:SS
    Return StringMid ( $_FileTime, 1 , 4 ) & '/' & StringMid ( $_FileTime, 5 , 2 ) & '/' & StringMid ( $_FileTime, 7 , 2 ) & _
    ' ' & StringMid ( $_FileTime, 9 , 2 ) & ':' & StringMid ( $_FileTime, 11 , 2 ) & ':' & StringMid ( $_FileTime, 13 , 2 )
EndFunc ;==> _ConvertTimeFormat ( )

the MsgBox show 1 and the console:

...
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
2015/11/27 09:22:37
+>21:41:08 AutoIt3.exe ended.rc:0
...

Again: build a runable reproducer script whitout AD which produce the error.

Edited by AutoBert
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...