Jump to content

GUICtrlCreateDate output - a different approach


Recommended Posts

Hi guys,

I've been struggling on this for hours... Because I took the time to look for every single topic related to this.

Everyone talks about changing the control style. But I'm not allowed to do that (not programatically, just practically speaking).

Here's the deal: I want to get a "valid date" from a GUICtrlCreateDate() control, but keep its visual style (long date format).

By Valid Date I mean a date that could be used in calculations with the Date User Defined Functions. The date would need to be in the format "yyyy/MM/dd".

If there's a "simple" way to do this I think it should be in the help file, in the form of an "example 4" for GUICtrlCreateDate()... (or I could be missing something...)

I can't use functions with String trimming and splitting or whatever because they run inoperable with different system languages...

So... any ideas yet? Not for me... :rolleyes:

Here's the snippet I've been working on:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
&#036ÕÝHÕRPÜX]J ][ÝÕÝ    ][ÝË

ÌLKLJBÕRTÙ]Û][
    ÌÍÑÕRôUdTåEô4Äõ4RÂgV÷C´4Äõ4T6Æ6¶VBgV÷C² ¢b33c´FFRÒuT7G&Ä7&VFTFFRgVÐìÈÀÀܼÀļÀÄÅÕ½Ðì°Ô°Ô°ÈÔÀ°ÈÔ¤)U%
ÑɱMÑ=¹Ù¹Ð ÀÌØíÑ°ÅÕ½ÐíUÁeDate") ; when choosing a new date, updates accordingly

$Label=GRPÝÜX]SX[
    ][ÝÙ[HX[  ][ÝËÌLLJHÈÝX[Èf÷&ÒFRWFFP ¢7&VvöâFöâb33·BvçBFòW&f÷&ÒF27GÆRWFFR&V6ÍÑ¡ÕÍȽ͸ÌäíÐɽ¹¥éÑ¡½ÉµÐåååä½54½(ìÀÌØíQ5}MQ=I5 = 0x1032
;$style = "yyyy/MM/dd"
;GUICtrlSendMsg($Start]K    ÌÍÑWÔÑUÔPU    ÌÍÜÝ[JBÙ[YÚ[ÛÕ]Q]J
BÕRTÙ]7FFR5uõ4õr ¥vÆR¢6ÆVW¥tVæ@ ¤gVæ2WFFTFFR²F2vÆÂÕÁÑÑ¡±°Ý¥Ñ Ñ¡¡½Í¸Ñ¸($ì$ݹѥÐѼ͡½ÜÑ¡Ñ¥¸valid format to use in calculations (like referred in the Date UDFs)
    GUICtÙ]]J  ÌÍÓX[ÕRPÝXY
    ÌÍÑ]JJB[[Â[ÈÓÔÑPÛXÚÙY

BW@¤VæDgVæ2³ÓÒfwC´4Äõ4T6Æ6¶V

thanks for your help!

Link to comment
Share on other sites

Hi guys,

I've been struggling on this for hours... Because I took the time to look for every single topic related to this.

Everyone talks about changing the control style. But I'm not allowed to do that (not programatically, just practically speaking).

Here's the deal: I want to get a "valid date" from a GUICtrlCreateDate() control, but keep its visual style (long date format).

By Valid Date I mean a date that could be used in calculations with the Date User Defined Functions. The date would need to be in the format "yyyy/MM/dd".

If there's a "simple" way to do this I think it should be in the help file, in the form of an "example 4" for GUICtrlCreateDate()... (or I could be missing something...)

I can't use functions with String trimming and splitting or whatever because they run inoperable with different system languages...

So... any ideas yet? Not for me... :rolleyes:

Here's the snippet I've been working on:

c2--><!--I2luY2x1ZGUgJmx0O0dVSUNvbnN0YW50cy5hdTMmZ3Q7CgpPcHQoJnXÔMÔUQUYL]Õ[XÖÜÒQÚVZQLTÌÔYÔÐ[ÛUÕ[ÒXudug¦D5§Es÷vtæ¤tÄ44Ô7vtÅDW43µeVÅE¥%&µc%¥sS´5¤ÔDÓ$óEe0£efY=YåQåQIMÝ)¹ÅÍDÝDÁáATÁY±©ÉY­)¹ÅÍDÝ--)¥5Ý5édÝIÁiMå%YMU8ÁxDcmVhdGVEYXRlKCZxdW
0OzIwMDcvMDEvMDEmcXVvdDssIDUsIDUsIDI1MCwgMjUpCkdVSUN0c^ÕÍLÐÖZQLÌÕÒPÖÎLÌUÖÑTÕ[XÖÜQÙÙPsf3&ÇU§&sVÆG&µ&ÄÄ4#4u&Dug¤tf¥#¤vÇU£'T6vöÔ¤¤æ§DÕt¦Æ$C¥VÄF!)ÍDÍ)±eaI±Q¥i]ݽ)¹ÅÍDÝiÅÝ!­¥i]ݵaYÙÍÍ5©Ý1Ý1$Å5
Ýå9M­=åÁXN0IGxhYmVsIHRvIHBlc
Zvcm0gdGhlIHVwZGF0ZQoKI3JlZ2lvbiBJIGRvbiYjMzk7dCB3YW50RRÛVÛLÙÚÞPÖÐXÑÔÕYÖ[UVÐQÕYÙÚPØVZ^ÍD4'¥tçe£#WVÕVvDvÄu§f6ÓD4#VUÃTÃäÃ%&´6§6Ô¤¤æ§DUdSeSeU&³5ET`¤C5!á55å
©Íµ%éé9©Ñé!±ÍiMå%
iáäÁ

thanks for your help!

I think you just need _DateTimeFormat

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi,

It is example 3 in the helpfile for the very function you mention; only problem is that it is wrong!

Here is corrected version.

;dateprob3.au3
#include <GUIConstants.au3>
#include <Date.au3>
ØØ[   ÌÍÑÕRHHÕRPÜX]J    ][ÝÑÙ]]I][ÝË
L
L
K   ÌÍÚÙ]HHuT7G&Ä7&VFTFFRôæ÷t6Æ4FFRÂRÂ#RÂÂ#¤uT6WE7FFR¤Fð b33c¶ÍôU%Ñ5Í ¤(%%ÀÌØíµÍôÀÌØí¡}ÑQ¡¸5Í ½à À°ÀÌØíµÍ°ÅÕt;Formatted Date as '2007/05/23' etc.." & @LF & "ÌÍÜÐÝXY]OI][ÝÈ   [ÈÑÜ^Q]J ÌÍÚÙ]JJB[[  ÌÍÛÙÒb33c´uTôUdTåEô4Äõ4P¤×6t&÷Âb33c¶×6rÂgV÷C´f÷&ÖGFVBFFR2b33³ÀÀܼÀÔ¼ÈÌÌäìѸ¸ÅÕ½ÐìµÀì1µÀìÅÕ½ÐìÀÌØíÍ
ÑɱIÑôÅÕ½Ðì& _DisplayDate($h_date))

Func _DisplayDate($h1_date);,$Ü]JBSØØ[   ÌÍÑWÔÑUÔPUHL
K   ÌÍÜÝ[LHH    ][ÝÞ^^^KÓSKFBgV÷C²Âb33c·7GÆS"ÒgV÷C¶FFFBÂBÔÔÔÒgV÷C³²b33c´EDÕõ4UDdõ$ÔBÁàÄÀÀÔ(%%Õѽ%ÑYÉÍ¥½¸±ÐìÅÕ½Ðì̸ȸÈÅÕ½ÐìQ¡¸($$ÀÌØíQ5}MQ=I5P 0x1005
    Elseif @UNICODE then 
        $DTM_SETFORMAT = 0x1032
    EndIf
    GUICtÙ[ÙÊ    ÌÍÚWÙ]K ÌÍÑWÔÑUÔPU    ÌÍÜÝ[LJBIÌÍÓ]Ñ]RÒuT7G&Å&VBb33c¶öFFR uT7G&Å6VæD×6rb33c¶öFFRÂb33c´EDÕõ4UD=I5P°À°ÀÌØíÍÑå±È¤(%IÑÕɸÀÌØí9ÝÑ)¹Õ¹ìôôÐí}¥ÍÁ±åÑ
Best, randall Edited by randallc
Link to comment
Share on other sites

@randallc

hello, thanks again you for your reply.

i've had the time to take a look at your script, and as I understand, it works as following:

- change style to yyyy/MM/dd

- write the specified date in the current style to a variable

- change style to dddd, dd MMMM yyyy

this however does not change the style back to what it was:

in some languages, there are words between day, month and year (like if you had "Monday, 2 of October of 2006", although it doesn't make much sense in english).

so i think the real question is.. is there a way to restore the exact default style of the date control?

Link to comment
Share on other sites

So... This took way too long but was fun and I learned some.

Thanks to Dale and lod3n for posted examples with hints. :rolleyes:

$js = ObjCreate("ScriptControl")
$js.language = "Jscript"
$sJS  = "var gsMonthNames=new Array('January','February','March','April','May','June','July','August','September','October','November','December');"
$sJS &= "var gsDayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');"
$sJS &= "Date.prototype.format=function(f){if(!this.valueOf())return ' ';var d=this;"
$sJS &= "return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|D|hh|nn|ss|a\/p)/gi,function($1){"
$sJS &= "switch($1){"
$sJS &= "case'yyyy':return d.getFullYear();"
$sJS &= "case'mmmm':return gsMonthNames[d.getMonth()];"
$sJS &= "case'mmm':return gsMonthNames[d.getMonth()].substr(0,3);"
$sJS &= "case'mm':return (d.getMonth()+1).toString().fill();"
$sJS &= "case'dddd':return gsDayNames[d.getDay()];"
$sJS &= "case'ddd':return gsDayNames[d.getDay()].substr(0,3);"
$sJS &= "case'dd':return d.getDate().toString().fill();"
$sJS &= "case'D':return d.getDate().toString();"
$sJS &= "case'hh':return ((h=d.getHours()%12)?h:12).fill();"
$sJS &= "case'nn':return d.getMinutes().toString().fill();"
$sJS &= "case'ss':return d.getSeconds().toString().fill();"
$sJS &= "case'a/p':return d.getHours()<12?'a':'p';"
$sJS &= "}});};String.prototype.fill=function(){return ('0'+this);};"
$js.Eval( $sJS )

$sJS = "var Date1 = (new Date()).format('dddd, mmmm dd, yyyy');"
$js.Eval( $sJS )
Local $Date1 = $js.Eval("Date1")
ConsoleWrite(@LF & "Format1: " & $Date1 & @LF)

$sJS = "var Date2 = (new Date()).format('mm/dd/yyyy');"
$js.Eval( $sJS )
Local $Date2 = $js.Eval("Date2")
ConsoleWrite("Format2: " & $Date2 & @LF)

$sJS = "var Date3 = (new Date()).format('dddd, D of mmmm of yyyy');"
$js.Eval( $sJS )
Local $Date3 = $js.Eval("Date3")
ConsoleWrite("Format3: " & $Date3 & @LF & @LF)

Maybe not quite all you want but it could be I think.

It is a start but it is Sunday night and I must quit for a while.

gsb

"Did you ever stop to think? ...and forget to restart!"
Link to comment
Share on other sites

  • 1 month later...

So... This took way too long but was fun and I learned some.

Thanks to Dale and lod3n for posted examples with hints. ;)

$js = ObjCreate("ScriptControl")
$js.language = "Jscript"
$sJS  = "var gsMonthNames=new Array('January','February','March','April','May','June','July','August','September','October','November','December');"
$sJS &= "var gsDayNames=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');"
$sJS &= "Date.prototype.format=function(f){if(!this.valueOf())return ' ';var d=this;"
$sJS &= "return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|D|hh|nn|ss|a\/p)/gi,function($1){"
$sJS &= "switch($1){"
$sJS &= "case'yyyy':return d.getFullYear();"
$sJS &= "case'mmmm':return gsMonthNames[d.getMonth()];"
$sJS &= "case'mmm':return gsMonthNames[d.getMonth()].substr(0,3);"
$sJS &= "case'mm':return (d.getMonth()+1).toString().fill();"
$sJS &= "case'dddd':return gsDayNames[d.getDay()];"
$sJS &= "case'ddd':return gsDayNames[d.getDay()].substr(0,3);"
$sJS &= "case'dd':return d.getDate().toString().fill();"
$sJS &= "case'D':return d.getDate().toString();"
$sJS &= "case'hh':return ((h=d.getHours()%12)?h:12).fill();"
$sJS &= "case'nn':return d.getMinutes().toString().fill();"
$sJS &= "case'ss':return d.getSeconds().toString().fill();"
$sJS &= "case'a/p':return d.getHours()<12?'a':'p';"
$sJS &= "}});};String.prototype.fill=function(){return ('0'+this);};"
$js.Eval( $sJS )

$sJS = "var Date1 = (new Date()).format('dddd, mmmm dd, yyyy');"
$js.Eval( $sJS )
Local $Date1 = $js.Eval("Date1")
ConsoleWrite(@LF & "Format1: " & $Date1 & @LF)

$sJS = "var Date2 = (new Date()).format('mm/dd/yyyy');"
$js.Eval( $sJS )
Local $Date2 = $js.Eval("Date2")
ConsoleWrite("Format2: " & $Date2 & @LF)

$sJS = "var Date3 = (new Date()).format('dddd, D of mmmm of yyyy');"
$js.Eval( $sJS )
Local $Date3 = $js.Eval("Date3")
ConsoleWrite("Format3: " & $Date3 & @LF & @LF)

Maybe not quite all you want but it could be I think.

It is a start but it is Sunday night and I must quit for a while.

gsb

Hi there! Sorry for the late reply... I didn't remember to reply in the proper time.

Let me tell you you're quite crazy ;)

Yes, that's another way, but it doesn't serve the purpose of adapting to several languages. It would make it more complicated than it is.

Unfortunately the solution above yours might be the best one. I say "unfortunately" because it seems that this control "can't" be reset. Maybe it can, buy I just don't know that much about controls and their handling.

Thanks to you all who took the time to enlighten me :);)

Link to comment
Share on other sites

Unfortunately the solution above yours might be the best one. I say "unfortunately" because it seems that this control "can't" be reset. Maybe it can, buy I just don't know that much about controls and their handling.

Thanks to you all who took the time to enlighten me :);)

Hi,

I think you can retrieve "default" setting from the registry too....

Best, Randall

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...