Jump to content

Recommended Posts

Posted

First of all sorry for my not so perfect english. What I'd like to do is program a date picker where user is presented with a box where he can enter numbers and function automatically converts it to date format. For example user would enter 01072010 and program would convert it to date format like 01.07.2010. Unfortunately I have no Idea how to do it. Could someone please point me in the right direction?

Posted (edited)

We've got better than that... Built in :mellow: (sort of)

#include <GuiDateTimePicker.au3>

; Create GUI
Local $hGUI = GUICreate("DateTimePick", 400, 300)
Local $hDTP = _GUICtrlDTP_Create($hGUI, 2, 6, 190)
GUISetState()

; Set the display format
_GUICtrlDTP_SetFormat($hDTP, "dd:MM:yyyy")

; Loop until user exits
While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Edit: changed format to what OP wanted

Edited by Mat
Posted

Yeah I know about that. But I'd like to modify that so that when you enter day it would automatically jump to months and then years without the need to press an arrow key.

Posted

On the other note. How do I get data from picker box. What I mean is how do I get the date picked in a variable so I can work with it?

  • 15 years later...
Posted (edited)

Dear @Gogi02, it may be that my code is very helpful for what you are looking for.聽馃

image.png.4c1593773358b32aeacc9ae1357d8332.png

image.png.a36a380c62a011172da64dcd9f6a506c.png

Seleccionar Fecha y Hora.au3

#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <DateTimeConstants.au3>
#include <MsgBoxConstants.au3>

; Activar declaraci贸n obligatoria de variables para evitar errores de ejecuci贸n.
Opt("MustDeclareVars", 1)

; Referencias de controles GUI.
Global $idDate, $idTime, $hTime, $btnAceptar

; Par谩metros de dise帽o.
Global $iTimeWidth = 220
Global $iMargin = 10
Global $iButtonWidth = 100
Global $iWinHeight = 130

; Dimensiones calculadas de la ventana.
Local $iWinWidth = $iTimeWidth + (2 * $iMargin)
Local $iButtonCenteredX = ($iWinWidth - $iButtonWidth) / 2

; Creaci贸n de la ventana principal.
GUICreate("Seleccionar Fecha y Hora", $iWinWidth, $iWinHeight)

; Control de selecci贸n de fecha.
$idDate = GUICtrlCreateDate("", $iMargin, 10, $iTimeWidth, 22)
_GUICtrlDTP_SetFormat(GUICtrlGetHandle($idDate), "dd'/'MM'/'yyyy")

; Control de selecci贸n de hora con ajuste manual.
Local $iTimeStyle = BitOR($DTS_TIMEFORMAT, $DTS_UPDOWN)
$idTime = GUICtrlCreateDate("", $iMargin, 44, $iTimeWidth, 22, $iTimeStyle)
$hTime = GUICtrlGetHandle($idTime)
_GUICtrlDTP_SetFormat($hTime, "HH:mm")

; Inicializaci贸n del selector con la hora actual.
Local $aNow[7] = [False, @YEAR, @MON, @MDAY, @HOUR, @MIN, 0]
_GUICtrlDTP_SetSystemTime($hTime, $aNow)

; Bot贸n de confirmaci贸n.
$btnAceptar = GUICtrlCreateButton("Aceptar", $iButtonCenteredX, 82, $iButtonWidth, 30)

; Mostrar interfaz.
GUISetState(@SW_SHOW)

; Gesti贸n de eventos.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $btnAceptar
            Local $sFecha = GUICtrlRead($idDate)
            Local $sHora  = GUICtrlRead($idTime)
            MsgBox($MB_ICONINFORMATION, "Resultado", "Fecha: " & $sFecha & @CRLF & "Hora: " & $sHora)
    EndSwitch
WEnd
Edited by tivp
Fix some bugs

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
×
×
  • Create New...