Valnurat

Can't compare dates

9 posts in this topic

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



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

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

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

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

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

#7 ·  Posted (edited)

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

#8 ·  Posted (edited)

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

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

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake