Sign in to follow this  
Followers 0
motormad

Date Formats

15 posts in this topic

Can sombody help me out with the syntx for a date format.

I would like the day in 2 digits - month in 2 digits - year in 4 digits.

Somthing like.

msgbox (day(now()) & month(now()) & year(now)) ) ??

I cant find it.

Share this post


Link to post
Share on other sites



_NowDate()

_DateTimeFormat()

_StringReplace()

StringRegExpReplace()

Share this post


Link to post
Share on other sites

MsgBox(0, "Date", StringFormat("%02d", @MDAY) & "-" & StringFormat("%02d", @MON) & "-" & @YEAR)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanx UEZ

It works but...

How do i get a specific date in the msgbox?

GUICtrlRead($MonthCal1)

the '$MonthCal1' is my date var.

How do i get my '$MonthCal1' date in @MDAY ?

Edited by motormad

Share this post


Link to post
Share on other sites

MsgBox(0, "Date", StringFormat("%02d", @MDAY) & "-" & StringFormat("%02d", @MON) & "-" & @YEAR)

Br,

UEZ

Even simpler

MsgBox(0, "Date", StringFormat("%02d-%02d-%d", @MDAY, @MON, @YEAR))

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thanx UEZ

It works but...

How do i get a specific date in the msgbox?

GUICtrlRead($MonthCal1)

the '$MonthCal1' is my date var.

How do i get my '$MonthCal1' date in @MDAY ?

What is $MonthCal1 actually returning? Can you give us an example?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Nice but...

How do i get my date in it.

Lets say 20-04-2010 ?

Thanks for you fast replys

$MonthCal1 = GUICtrlCreateMonthCal("2010/10/21", 442, 50, 169, 158)

Edited by motormad

Share this post


Link to post
Share on other sites

You mean this:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Date, $msg
    GUICreate("Get date", 210, 190)

    $Date = GUICtrlCreateMonthCal("1953/03/25", 10, 10)
    GUISetState()

    ; Run the GUI until the dialog is closed or timeout

    Do
        $msg = GUIGetMsg()
        If $msg = $Date Then MsgBox(0, "debug", "calendar clicked")
    Until $msg = $GUI_EVENT_CLOSE

    MsgBox(0, $msg, StringRegExpReplace(GUICtrlRead($Date), "(\d+)/(\d+)/(\d+)", "$3-$2-$1"), 2)
EndFunc ;==>Example

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Or another example that still uses StringFormat()

GUICreate("Date Test")

$hdate = GUICtrlCreateDate("2010/10/21", 20,20, 100, 20, 0x00)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $hdate

            $aDate = StringSplit(GUICtrlRead($hdate), "/")
            MsgBox(0, "Date", StringFormat("%02d-%02d-%d", $adate[2], $adate[1], $adate[3]))
    EndSwitch
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

If you are going to use the drop-down calendar to select a date you set it to return the selected date in the format you want directly

#include <GuiDateTimePicker.au3>

    $hGui = GUICreate("Date Test")

    $hdate = GUICtrlCreateDate("2010/10/21", 20,20, 100, 20, 0x00)
    $hWndDate = ControlGetHandle($hGui, "", $hdate)
    _GUICtrlDTP_SetFormat($hWndDate, "dd-MM-yyyy")
    GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $hdate
            MsgBox(0, "Selected Date", GUICtrlRead($hdate))
    EndSwitch
WEnd

Another example

#include <GuiDateTimePicker.au3>

    $hGui = GUICreate("Date Test")

    $hdate = GUICtrlCreateDate("2010/10/21", 20,20, 100, 20, 0x00)
    $hWndDate = ControlGetHandle($hGui, "", $hdate)
    _GUICtrlDTP_SetFormat($hWndDate, "dddd dd-MMMM-yyyy")
    GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $hdate
            MsgBox(0, "Selected Date", GUICtrlRead($hdate))
    EndSwitch
WEnd

Edit: added second example

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Yes ;)

Thats it thanx :)

Also i will use

Opt('MustDeclareVars', 1)

In the future

and learn more about

StringRegExpReplace

;)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Yes Bowmore.

I think its the best way because you handle the problem in the beginning.

But ... I dont understand it ;)

ALso... now i have to send 29102010 in the program and not 29-10-2010

How do i do that.

I try whit

StringRegExpReplace(GUICtrlRead($aSTA[1]), "(\d+)/(\d+)/(\d+)", "$3$2$1"))
in the place of
StringRegExpReplace(GUICtrlRead($aSTA[1]), "(\d+)/(\d+)/(\d+)", "$3-$2-$1"))

the GUICtrlRead($aSTA[1]) is the value with 29-10-2010 in it

but it wont work.

Edited by motormad

Share this post


Link to post
Share on other sites

With my example above the line

MsgBox(0, $msg, StringRegExpReplace(GUICtrlRead($Date), "(\d+)/(\d+)/(\d+)", "$3$2$1"), 2)

is working as you want -> ddmmyyy

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Yes Bowmore.

I think its the best way because you handle the problem in the beginning.

But ... I dont understand it ;)

ALso... now i have to send 29102010 in the program and not 29-10-2010

How do i do that.

I try whit

StringRegExpReplace(GUICtrlRead($aSTA[1]), "(\d+)/(\d+)/(\d+)", "$3$2$1"))
in the place of
StringRegExpReplace(GUICtrlRead($aSTA[1]), "(\d+)/(\d+)/(\d+)", "$3-$2-$1"))

the GUICtrlRead($aSTA[1]) is the value with 29-10-2010 in it

but it wont work.

StringRegExpReplace(GUICtrlRead($aSTA[1]), "-", ""))


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Thank you all people ;)

it works fine now

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  
Followers 0