Jump to content

Can AutoIt tell me the current short date format?


c.haslam
 Share

Recommended Posts

Thank you for your reply.

I rephrase my question:

  • GUICtrlCreateDate with $DTS_SHORTDATEFORMAT returns a date in my PC's short-date format
  • On my PC, I have set the short date format to yyyy-mm-dd
  • Using StringSplit, my code separates out year, month and day
  • I give the script to a friend whose short-date format is different, e.g. mm-dd-yyyy
  • So my code mixes up year, month and day
  • So my code needs know what format a PC is using.
  • How do I get a PC's short-date format so there will be no mixe up in my code?

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Here is a script excerpted from a much longer script that shows what I need to do:

CODE
#include <GUIConstants.au3>

Global $dlgXCopy = GUICreate("XCopy", 588, 705, -1,-1) ; centred

Global $inpDate = GUICtrlCreateDate("", 144, 232, 81, 25, $WS_TABSTOP)

Global $btnExecute = GUICtrlCreateButton("Execute", 520, 672, 57, 25, 0)

Global $btnCancel = GUICtrlCreateButton("Cancel", 434, 672, 57, 25, 0)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE,$btnCancel

ExitLoop

Case $btnExecute

DoExecute()

EndSwitch

WEnd

GUIDelete()

Func DoExecute()

$t = GUICtrlRead($inpDate)

; need to replace this with call to function that returns

; setting in Control Panel | REgional Options | Date

$dateformat = "yyyy-mm-dd"

Switch $dateformat

Case "yyyy-mm-dd"

$ar = StringSplit($t,"-",0) ; characters

$mon = $ar[2]

$day = $ar[3]

$yr = $ar[1]

Case "mm/dd/yyyy"

$ar = StringSplit($t,"/",0) ; characters

$mon = $ar[1]

$day = $ar[2]

$yr = $ar[3]

Case Else ; other date formats

EndSwitch

MsgBox(0,"","mon "&$mon&" day "&$day&" year "&$yr)

EndFunc

The Date control should offer the user the date format his PC is using, not force him to use a format the script dictates.

Sorry about the lack of indents. The script has them in SciTe, but not here.

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <WindowsConstants.au3>

Global $dlgXCopy = GUICreate("XCopy", 588, 705, -1, -1) ; centred
Global $inpDate = GUICtrlCreateDate("", 144, 232, 81, 25, $WS_TABSTOP)
Global $btnExecute = GUICtrlCreateButton("Execute", 520, 672, 57, 25, 0)
Global $btnCancel = GUICtrlCreateButton("Cancel", 434, 672, 57, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $btnCancel
            ExitLoop
        Case $btnExecute
            DoExecute()
    EndSwitch
WEnd
GUIDelete()

Func DoExecute()
    $aDate = _GUICtrlDTP_GetSystemTime(GUICtrlGetHandle($inpDate))
    $mon = $aDate[1]
    $day = $aDate[2]
    $yr = $aDate[0]
    MsgBox(0, "", "mon " & $mon & " day " & $day & " year " & $yr)
EndFunc   ;==>DoExecute

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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...