Jump to content
Sign in to follow this  
gritts

Copying from one date time field results in time change

Recommended Posts

gritts

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
abberration

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
gritts

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
abberration

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
jchd

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
gritts

@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  

  • Similar Content

    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • Rskm
      By Rskm
      Hi, for a script of mine, I wish to keep a time frame on till how the program will work.. basically, I want the program to read the date and if the read date < 'a particular date', the program continues, else it exit. I don't want to read the time from the computer as the program can be fooled by resetting the pc time. is there a way to read time from internet - so that the user cannot fool the program by date reset? thanks
    • Rskm
      By Rskm
      Hi, i have a variable (floating number - could be positive or negative), i wish to print it into a text file, how can i keep the format in such a way that it always has 4 digits ahead of decimal and 2 after decimal
      basically i have total 7 columns in the text file to print the variable  ;
      eg: variable = 1.235, output requied = 0001.24
      variable=-23.55555, output required =-023.56
    • nacerbaaziz
      By nacerbaaziz
      Hello
      Dear Sirs, I have a question please
      About UPDown ctrl
      Where I want to adjust its format
      For example, I want to create a window to set the clock like the window in the system
      Can this be done?
      here's the example
      ______

      #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <UpDownConstants.au3> goto() func Goto() local $wGoto = GUICreate("go to spissific position", 250, 180, @DesktopWidth / 2 - 192, @DesktopHeight / 2 - 235, -1) GUICtrlCreateLabel("please write a corect position to go to it", 50, 10, 220, 20) GUICtrlCreateLabel("hours", 0, 80, 100, 30) local $Inp1 = GUICtrlCreateInput("00", 0, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp1, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 23, 0) GUICtrlCreateLabel("minuts", 110, 80, 100, 30) local $Inp2 = GUICtrlCreateInput("00", 110, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp2, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) GUICtrlCreateLabel("seconds", 220, 80, 100, 30) local $Inp3 = GUICtrlCreateInput("00", 220, 90, 100, 20, $ES_NUMBER + $WS_TABSTOP)     GUICtrlCreateUpdown($Inp3, $UDS_ARROWKEYS) GUICtrlSetLimit(-1, 60, 0) local $Ok = GUICtrlCreateButton("&ok", 0, 150, 50, 30, 0x01) local $cancel = GUICtrlCreateButton("&cancel", 200, 150, 50, 30) GUISetState(@sw_show, $WgoTo) while 1 switch GUIGetMSG() case $GUI_Event_Close, $cancel exit case $OK local $read1 = GUICtrlRead($inp1) if $read1 >= 1 then $Read1 = ($Read1*60)*60 local $read2 = GUICtrlRead($inp2) if $read2 >= 1 then $Read2 = $Read2*60 local $read3 = GUICtrlRead($inp3) GUIDelete($WgoTo) Return $read1+$read2+$read3 exit endSwitch Wend EndFunc
      ________
      What I need is to be the contents of the inputs as follows when i change the value of the UPDown CTRL
      00
      01
      02
      03
      ...
       
    • Shedunn
      By Shedunn
      I've been looking through some different functions(not sure if that's the right word) to get the Date and time and I can't find one that doesn't include "/ " or ":" in what is returned.

      I'm trying to create a file name with this format "QuickConfig_MMDDYYYY_HHMM"  (doesn't matter if 24 or 12hr format)
      #include <Date.au3> Func _SaveConfig MouseClick('primary',155, 46, 1, 0) ;clicks save as WinWait('Save bluePRINT Configuration As...','', 4) MouseClick('primary',632, 47, 1, 0) ;clicks the file path bar $Documents = @MyDocumentsDir $FilePath = $Documents & '\BP3 Configs' Send($FilePath) Send('{ENTER}') MouseClick('primary',166, 580, 1, 0) ;clicks file name bar $FileName = 'QuickConfig_' & _NowDate & '_' & _NowTime Send($FileName) Send('{ENTER}') EndFunc  
       
      I'm wondering if there is a function somewhere to do this?
×