Jump to content
Sign in to follow this  
gritts

Copying from one date time field results in time change

Recommended Posts

I searched for this oddity for a while but found no results. If I missed it, my apologies.

I have an app that I am building that will eventually search a SQL database for results within a specified range of time. To collect the range of time required but the user, I have 2 fields I created, one for start and the other for end times. They are formatted "yyyy/MM/dd HH:MM:ss" for entry.

The fields are created with this:

$dpStartDate = GUICtrlCreateDate(_NowCalc(), 112, 88, 146, 24)
$dpEndDate = GUICtrlCreateDate(_NowCalc(), 416, 88, 146, 24)
I am setting the format of the fields with this code:
$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
$style = "yyyy/MM/dd  hh:mm:ss"
GUICtrlSendMsg($dpStartDate, $DTM_SETFORMAT_, 0, $style)
GUICtrlSendMsg($dpEndDate, $DTM_SETFORMAT_, 0, $style)

What I am attempting to do is when the start field is updated, compare it with the end time field. If the end time is less than the start time, make both fields match. When I attempt to do so with the function below, The end time date is copied correctly but the time (hour) is reset to 1, no matter the time entered. Am I going about updating the field incorrectly?

As an example, I set the date in the start field to "2013/08/23 11:47:38", the end time field gets set to "2013/08/23 01:00:00"

Func dpStartDateChange()
    Local $stDT = GUICtrlRead($dpStartDate), $edDT = GUICtrlRead($dpEndDate)
    If $edDT < $stDT Then
        MsgBox(0,"Change Needed","End Time: "&$edDT&@CRLF&"Start Time: "&$stDT) ;Shows correct time
        GUICtrlSetData($dpEndDate,$stDT)
    EndIf
EndFunc

There is no code for SQL in place yet. I am working on some of the GUI logic for now. Let me know if there is enough code here or you need more.

Share this post


Link to post
Share on other sites

You had the answer with your 2nd box of code. Example:

#include <GUIConstants.au3>
#include <date.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 352, 82)
$dpStartDate = GUICtrlCreateDate(_NowCalc(), 16, 16, 186, 21)
$dpEndDate = GUICtrlCreateDate(_NowCalc(), 16, 40, 186, 21)
$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
$style = "yyyy/MM/dd  hh:mm:ss"
GUICtrlSendMsg($dpStartDate, $DTM_SETFORMAT_, 0, $style)
GUICtrlSendMsg($dpEndDate, $DTM_SETFORMAT_, 0, $style)
$Button1 = GUICtrlCreateButton("Read", 232, 24, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $stDT = GUICtrlRead($dpStartDate), $edDT = GUICtrlRead($dpEndDate)
            If $edDT < $stDT Then
                MsgBox(0,"Change Needed","End Time: "&$edDT&@CRLF&"Start Time: "&$stDT) ;Shows correct time
;~                 GUICtrlSetData($dpEndDate,$stDT) ; Do not use
                GUICtrlSendMsg($edDT, $DTM_SETFORMAT_, 0, $style) ; correct way
            EndIf
    EndSwitch
WEnd

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Thank you for the reply.

I tried the suggestion you made and the field does not update with the change. I also tried running your sample code and it had the same effect. The value from the start time is not copied to the end time. Here is my function as it stands now...

Func dpStartDateChange()
    Local $stDT = GUICtrlRead($dpStartDate), $edDT = GUICtrlRead($dpEndDate)
    If $edDT < $stDT Then
        MsgBox(0,"Change Needed","End Time: "&$edDT&@CRLF&"Start Time: "&$stDT)
        GUICtrlSendMsg($dpEndDate,$DTM_SETFORMAT_,0,$style)
    EndIf
EndFunc

I'm still trying to wrap my head around the "GUICtrlSendMsg" function...

Share this post


Link to post
Share on other sites

I did not fully understand what you were trying to accomplish. Now I do. I have tried several things even after reading this part of the help file on GuiCtrlSetData:

The "data" date format is "yyyy/mm/dd".

Therefore, if you include the time afterwards, it does not accept it. Since the _NowCalc() function was able to set the date and time, I thought maybe the data needed to be encoded as a date format instead of a string. I tried using _Date_Time_EncodeSystemTime, but that did not work. All it did was to set the end time back to the current time.

Sorry I could not find a solution.


RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Try this, it works for me. You may want to change the time format if your locale uses AM/PM (which mine doesn't). See msdn details.

#include <GUIConstants.au3>
#include <date.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 352, 82)
$dpStartDate = GUICtrlCreateDate(_NowCalc(), 16, 16, 186, 21)
$dpEndDate = GUICtrlCreateDate(_NowCalc(), 16, 40, 186, 21)
$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
$style = "yyyy'/'MM'/'dd' 'HH':'mm':'ss"
GUICtrlSendMsg($dpStartDate, $DTM_SETFORMAT_, 0, $style)
GUICtrlSendMsg($dpEndDate, $DTM_SETFORMAT_, 0, $style)
$Button1 = GUICtrlCreateButton("Read", 232, 24, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $stDT = GUICtrlRead($dpStartDate), $edDT = GUICtrlRead($dpEndDate)
            If $edDT < $stDT Then
                MsgBox(0,"Change Needed","End Time: "&$edDT&@CRLF&"Start Time: "&$stDT) ;Shows correct time
                GUICtrlSetData($dpEndDate,$stDT)
            EndIf
    EndSwitch
WEnd

As the page says, non-format characters need to be enclosed in single quotes.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

@abberration, thank you for your help, You gave me some ideas when searching for the solution.

@jchd, I ran your sample script and it worked fine. After a time of "stare and compare" between what you posted and what I had, I could not figure what the difference was aside from the single tick quotes for non-format characters. I copied your "$style" line into my script and it worked. To cut a long story short, I discovered my version had an extra space between the date format and the time format.

Here are the two lines for comparison...

$style = "yyyy'/'MM'/'dd'  'HH':'mm':'ss" ;my version
$style = "yyyy'/'MM'/'dd' 'hh':'mm':'ss" ;new version

The field seems to update fine whether I use the 24hour or 12hour formatting ("HH" or "hh"). Funny what having one extra space can do. Thank you both again for your help!

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
    • By TheDcoder
      Hi everyone,
      I am bit stumped as to why I am not able to set the time in the Date control
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm:ss" GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ; Set time Local $iRet = GUICtrlSetData($idDate, '13:33:37') ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:
      But I get failure
      What gives?
      Thanks for the help in advance!
    • By Colduction
      Hi guys, i want to convert WebKit/Chrome timestamps that i've found in chrome cookie database to Human-Readable time (if possible, with UTC or GMT offset).
      Example of WebKit/Chrome timestamp: 13228999534132232 Output that i want: 2020-03-18 20:16:56 This site has a tool to do this work, but i wonder how to convert this time (this timestamp's time bases are 1600/01/01) to human-readable time:
      https://www.epochconverter.com/webkit
    • By Inpho
      Hi All,
      I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
      String functions:
      #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
      ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)  
×
×
  • Create New...