Jump to content
Valnurat

Can't compare dates

Recommended Posts

Valnurat

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.

Share this post


Link to post
Share on other sites
Jos

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

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Valnurat

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.

Share this post


Link to post
Share on other sites
AutoBert

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.

Share this post


Link to post
Share on other sites
Valnurat

When I do this:

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

I get the result in the attachment.

FileGetTime.JPG


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
AutoBert

when you run my small example in Post #4 what's the output in console, and what's show in the MsgBox?

As i can't test your small script snipet (unpopulatet array) please make a small reproducer in which the error occurs.

Share this post


Link to post
Share on other sites
Valnurat

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.

Share this post


Link to post
Share on other sites
AutoBert

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

Share this post


Link to post
Share on other sites
Valnurat

For some reason I got it to work.

I tried split every command up 1 by 1 and now it works, I have absolute no idea why it is working now.

But thank you for the help anyway.


Yours sincerely

Kenneth.

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

  • Similar Content

    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
    • sumanth1980
      By sumanth1980
      Here i am wrote a simple lines to install basic applications but when i clicked on one application/program to install it was working fine but when i cancel the program in the middle to install another program it was not working. I am not an expert in this but i want a solution for this ... Can any one help me on this....
      ORG-1.au3
    • PleaseHelpMEIWillLoveyou
      By PleaseHelpMEIWillLoveyou
      Is there a way to use a custom terminal or something from my pc and run a script on another pc.
      please let me know if its possible
      (not for anything bad just for a project im working on)
    • juniq
      By juniq
      Hey I'm writing on a script which places a link in the context menu so you can choose several mp3 files and rename them using id3 tag udf and year / time stuff variables.
      My problem: I'm renaming the files through "FileMove", But HOW can I get the current directory of the chosen files only? I can't use stringsplit cz there are more than 1 delimiter "\". and I can't trim the string because the stringlength changes every time. How can I get ONLY the directory where the files from $cmdline chosen are? 
×