Jump to content
great77

Date Diffrence between _NowCalc() and FileGettime

Recommended Posts

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

Share this post


Link to post
Share on other sites
TheSaint

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.

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@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
  • Like 1

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
great77
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]

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@great77
Happy to have helped :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

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

    • greichert
      By greichert
      I am running the following code:
      DirRemove("C:\Desktop\Install.zip",1) I don't receive an error but the folder is not deleted. If i run this same script on a non zipped folder it works fine. Does DirRemove not work for zipped files? If not is there a way to delete them?
    • Haselnuzz
      By Haselnuzz
      Hi and Hello from a Noob..:-)
      i have a very weird problem. I fill up a 2d array with a)numbers and b)letters from A-Z, so 2 columns. This works absolutely perfect. But as soon as i try to sort them (numbers ascending) the array ends up in some kind of "String-sortation". What exactly am i doin wrong? To make it easy, i post below the piece of code, which i am talking about. Hope that someone can help me out.
      Func Analyse()
          Local $BasisArray[0]
          Local $aFill = "A" & "|B" & "|C" & "|D" & "|E" & "|F" & "|G" & "|H" & "|I" & "|J" & "|K" & "|L" & "|M" & "|N" & "|O" & "|P" & "|Q" & "|R" & "|S" & "|T" & "|U" & "|V" & "|W" & "|X" & "|Y" & "|Z"
          _ArrayAdd ($BasisArray, $afill)
          Local $FreqArray[0][2]=[[]]
       
          $row = 0

          For $i = 0 to 25
       
              $fummel = _ArrayToString ($BasisArray, ":" , $row, $row)
              $readout = _GUICtrlRichEdit_GetText ($hRichEdit)
              $anzAs = stringreplace ($readout, $fummel, $fummel)
              $extended = @extended
              $FreqFill = $extended & "|" & $fummel
              _ArrayAdd($FreqArray, $FreqFill)
       
              $row = $row + 1
          Next
          _ArrayDisplay($FreqArray, "2D - Item delimited")
          _ArraySort($FreqArray)
          _ArrayDisplay($FreqArray, "bla")
       
       
      Thanks for helping me,
       
      Cheers,
       
      Patrick
    • greichert
      By greichert
      I am running an exe, that copies a seperate exe (test123.exe)from my computer and puts it onto a remote server "testserver". Everything  works fine up to this point. I need to run this copied exe (test123.exe) on "testserver" but it keeps running on my computer instead. The code I am using to run the exe is below. What am I doing wrong? How can I get this executable to run on the remote server and not my home computer?
      RunWait( "\\testserver.domain.com\c$\user1\greichert\Desktop\InstallEXE\InstallEXE\test123.exe","\\testserver.domain.com\c$\Users\user1\Desktop\InstallEXE\InstallEXE");run exe  
    • greichert
      By greichert
      I am trying to stop a windows service on a separate server than where my script is running. When I run the following script on the same server as the service I need to stop, it works fine. 
      RunWait(@ComSpec & " /c net stop FascetAgentfv2", @ScriptDir, @SW_HIDE);stop agent But when I change "@ScriptDir" to ""\\newserver\c$\Program Files\test\" and run it on my server nothing happens. I tried to error handle and all it was returning was "2". Any suggestions?
    • ufukreis1212
      By ufukreis1212
      Hello, I am new members. Help me please. I want vbs convert to au3 .
      This vbs code : 
      'deneme Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") strOSArch = GetObject("winmgmts:root\cimv2:Win32_OperatingSystem=@").OSArchitecture Set objNetwork = CreateObject("Wscript.Network") Set wshShell = CreateObject( "WScript.Shell" ) strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) Set oShell = WScript.CreateObject("WScript.Shell") proc_arch = oShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") Set oEnv = oShell.Environment("SYSTEM") strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colMB = objWMIService.ExecQuery("Select * from Win32_BaseBoard") Set colCSes = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItemsx = objWMIService.ExecQuery( _ "SELECT * FROM Win32_VideoController",,48) '------------------------------------------------------------------- Set obj = GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory") i = 1 For Each obj2 In obj memTmp1 = obj2.capacity / 1024 / 1024 TotalRam = TotalRam + memTmp1 i = i +1 Next '-------------------------------------------------------------------- Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Architecture from Win32_Processor") For Each objItem in colItems if objItem.Architecture = 0 then strArchitecture = "x86" end if if objItem.Architecture = 9 then strArchitecture = "x64" end if next '-------------------------------------------------------------------- strComputer = "." ' Local computer strMemory = "" i = 1 set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory") For Each objItem In colItems if strMemory <> "" then strMemory = strMemory & vbcrlf strMemory = strMemory & "Bank" & i & " : " & (objItem.Capacity /1024 /1024) & " Mb" i = i + 1 Next installedModules = i - 1 Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray") For Each objItem in colItems totalSlots = objItem.MemoryDevices Next '---------------------------------------------------------------------- Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" ) Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem" ) For Each objItem in colItems strComputerDomain = objItem.Domain Next for each System in SystemSet For Each objItem in colItemsx For Each objProcessor in colProcessors For Each bbType In colMB MbVendor = bbType.Manufacturer MbModel = bbType.Product MsgBox "İşletim Sistemi : " & System.Caption & vbNewLine & _ "İşletim Sistemi Versionu : " & + System.Version & vbNewLine & _ "Windows Mimari Yapısı: " & strOSArch & vbNewLine & _ "Kullanıcı isminiz: " & objNetwork.UserName & vbNewLine & _ "Bilgisayar ismi: " & strComputerName & vbNewLine & _ "Çalışma Grubu: " & strComputerDomain & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Anakart: " & MbVendor & " " & "[" & MbModel & "]" & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Grafik Kartı: " & objItem.Caption & vbNewLine & _ "Driver Version: " & objItem.DriverVersion & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "İşlemci Üreticisi: " & objProcessor.Manufacturer & vbNewLine & _ "İşlemci İsmi: " & objProcessor.Name & vbNewLine & _ "CPU Mimarisi: " & strArchitecture & vbNewLine & _ "İşlemci Çekirdek sayısı: " & oEnv("NUMBER_OF_PROCESSORS") & vbNewLine & _ "--------------------------------------" & vbNewLine & _ "Toplam RAM: " & TotalRam & " MB" & vbNewLine & _ "Toplam Slot: " & totalSlots & vbNewLine & _ "Boş Slot: " & (totalSlots - installedModules) & vbNewLine & _ "Ramlerin bulunduğu slotlar:" & vbcrlf & strMemory,0,"deneme" Next Next Next Next please help me , thanks.
×