ur

Date difference is not working

4 posts in this topic

I am assigning the current time stamp to a variable $strtTime and holding the execution for 5 seconds with Sleep and calculating the current time stamp.

Ideally, the _DateDiff should give 5 seconds as output as i gave the parameter as s.But it is giving zero 0.

Any suggestions....!

Global $startTime = _Date_Time_GetLocalTime()

$startTime = _Date_Time_SystemTimeToDateTimeStr($startTime)

Sleep(5000)
    $tCur = _Date_Time_GetLocalTime()
    $tCur = _Date_Time_SystemTimeToDateTimeStr($tCur)

$iDateCalc = _DateDiff('s', $startTime, $tCur)
    MsgBox(0,"$iDateCalc",$iDateCalc)
    FileWrite ($QTPfile,CHr(34) & $tCur & CHr(34) & Chr(44) & """" & $iDateCalc & """,")

 

Share this post


Link to post
Share on other sites



Append this:

ConsoleWrite('DateDiff; '&$startTime & @TAB &  $tCur & @TAB & $iDateCalc&@CRLF)

run script, and have a look in console and in helpfile => _DateDiff. If you don't understand why you get 0 post console output.

Share this post


Link to post
Share on other sites

My systemTimeToDateTimeStr returns the date and time in the format mm/dd/yyyy hh:mm:ss which is not the format that DateDiff requires, yours may be a similar problem.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

It is all about the format of date functions. Try it like this:

$startTime = _NowCalc()
    Sleep(5000)
    $tCur = _NowCalc()
    $iDateCalc = _DateDiff('s', $startTime, $tCur)
    MsgBox(0,"",$iDateCalc)

 

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

    • kawliga751
      By kawliga751
      I have established how to get tomorrows date however I can't seem to figure out how to format the date into my required format of MM/DD/YYYY.  
      I have this:
      $today=_DateToDayValue(@YEAR,@MON,@MDAY) Dim $Y, $M, $D $tomorrow=_DayValueToDate($today+1, $Y, $M, $D) The _DateToDayValue seems to have a fixed format.  I've also tried a :
      $vardate = _DateAdd( 'd',1, _NowCalcDate()) with a "StringSplit" and/or StringFormat but the _NowCalcDate seems to also be fixed to a YYYY/MM/DD format.
      I'm sure I'm missing something simple but am at a loss.
      Any help would be MUCH appreciated
       
       
    • DavidLago
      By DavidLago
      Guys,
      I'm experiencing something hard to understand in this code: 
      Why it gives me 0 when I use the variable? It looks JUST like the string that I used for calc.
      I had to add two different date treatments to run in servers with different languages.
      #include <Date.au3> #include <Constants.au3> #include <Array.au3> ;All variables Global $line, $sRealResult, $aArray, $sDateHour, $aValues, $sValue1, $sValue2, $aArrayY, $aArrayM, $aArrayD, $sDataFinalBR, $sDataFinalEN funcCalcDateLocal() Func funcCalcDateLocal() Local $LocalTime = 'NET TIME \\localhost | findstr /C:"hora" | findstr /v "^$"' ;Command to execute $bResult = Run(@ComSpec & " /c " & $LocalTime, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Execute the command While 1 $line = StdoutRead($bResult) If $line <> "" Then ;Eliminate the first blank result $sRealResult = $line If @error Then ExitLoop ExitLoop EndIf WEnd StdioClose($bResult) EndFunc ;==>funcCalcDateLocal $aArray = StringSplit($sRealResult, ' ‚ ', 1) ;Eliminate the comma and split it $sDateHour = $aArray[2]; this is the date " " hour $aValues = StringSplit($sDateHour, ' ', 1) ;Split them $sValue1 = $aValues[1] ; Then Date $sValue2 = $aValues[2] ; and Hour $aArrayDate = StringSplit($sValue1, '/', 1) ;Split them in order to later place them in the right sequence for the servers with different languages $aArrayY = $aArrayDate[3] ; year $aArrayM = $aArrayDate[2] ; month $aArrayD = $aArrayDate[1] ; day $sDataFinalBR = $aArrayY & "/" & $aArrayM & "/" & $aArrayD & " " & $sValue2 ; Server PT-BR final date $sDataFinalEN = $aArrayY & "/" & $aArrayD & "/" & $aArrayM & " " & $sValue2 ; Server EN-US final date MsgBox(64, "Data BR", $sDataFinalBR) MsgBox(64, "Data EN", $sDataFinalEN) Local $iDateCalc1 = _DateDiff('s', $sDataFinalBR, "2017/04/19 16:02:52") ; test 1 Local $iDateCalc2 = _DateDiff('s', "2017/04/19 16:02:52", $sDataFinalBR) ; test 2 Local $iDateCalc3 = _DateDiff('s', "2017/04/19 16:02:52", "2017/04/19 16:02:53") ; test 3 MsgBox(64, "Date Calc - Test 1", $iDateCalc1) MsgBox(64, "Date Calc - Test 2", $iDateCalc2) MsgBox(64, "Date Calc - Test 3", $iDateCalc3)  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I was trying to replace 2 identical characters from a string, but I didn't manage to with StringReplace()...
      Does anyone know how to replace two ( i.e. : """" with ";" ) ? 
      Thanks  
    • Paranthaman
      By Paranthaman
      Hi,
      I want to click a link by the element ID through IEGetObjById.
      <!DOCTYPE html> <html> <body> <button type="button" id="Random-1-ID" onclick="alert('Hello world!')"></button> </body> </html> I intend to click the button with ID"Random-1-ID". But on every refresh the ID changes to next number like "Random-2-ID" "Random-3-ID"
       
      The code i which i wrote for this function is
      #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("I:\Documents\1. Work\Automation\My codes\Collections\11. Clicking button by Value and ID\button.html") Local $oDiv = _IEGetObjById($oIE, "Random-1-ID") _IEAction($oDiv, "click") _IELoadWait($oIE) So can anyone help me to alter this code like it clicks for every ID in format "Random-%-ID"
    • ur
      By ur
      To get the current time stamp, I got the below code.
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #RequireAdmin ; Under Vista the Windows API "SetSystemTime" may be rejected due to system security $td = _Date_Time_GetSystemTime() $td = _Date_Time_SystemTimeToDateTimeStr($td) $td = StringReplace($td, " ", "_") $td = StringReplace($td, ":", "_") MsgBox(0,"",$td) But it is not giving the date or time of the timezone where the system is there.
      Please suggestt