TDatePick

Source: source/classes/tdtpicke.prg

Inherits from: TControl

TDatePick wraps the Windows date and time picker common control (SysDateTimePick32). It provides a drop-down calendar for date selection and supports both date-only and date-time modes with configurable display formats, range restrictions, and multi-select capability.

Command Syntax

@ nRow, nCol DTPICKER oDtp VAR dDate SIZE nW, nH PIXEL OF oWnd ;
   PICTURE cFmt ON CHANGE bBlock

Key DATA Members

DATATypeDescription
lDateTimeLogicalEnable date-time mode (T value) instead of date-only
cPictureCharacterDisplay format picture (e.g., "dd/mm/yyyy")
lMultiSelectLogicalEnable multi-date selection in the drop-down calendar
lNoTodayLogicalHide the "Today" button at the bottom of the drop-down
nMaxSelDaysNumericMaximum number of selectable days in multi-select mode
lWeekNumbersLogicalShow week numbers in the drop-down calendar
lNoTodayCircleLogicalHide the circle around today's date in the drop-down
lNoTrailingDatesLogicalHide dates from previous/next months

Methods

MethodDescription
New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate, bWhen, bChange, nHelpId, cPic, nStyle )Create a new TDatePick control
ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack, oFont, oCursor, cMsg, lUpdate, bWhen, bValid, bChanged, cPic )Redefine from dialog resource
SetDate( dDate, lEmpty )Set the picker to a specific date (optionally allow empty)
GetDate()Retrieve the currently selected date or datetime value
SetRange( dFrom, dUpto )Restrict the selectable date range
GetRange()Retrieve the current minimum and maximum date range
Open()Programmatically open the drop-down calendar
cText( uVal )Get or set the formatted text value (SETGET)
Refresh()Refresh the control from the bound variable
Change()Execute the bChange code block

Examples

Date Picker with Format

#include "FiveWin.ch"

function Main()

   local oWnd, oDtp, dDate := Date()

   DEFINE WINDOW oWnd TITLE "Date Picker Demo" SIZE 350, 200

   @ 40, 30 DTPICKER oDtp VAR dDate SIZE 120, 22 PIXEL OF oWnd ;
      PICTURE "dd/mm/yyyy" ;
      ON CHANGE MsgInfo( DToC( dDate ), "Date Changed" )

   oDtp:SetRange( Date() - 365, Date() + 365 )

   @ 100, 30 BUTTON "&Get Date" SIZE 80, 25 PIXEL OF oWnd ;
      ACTION MsgInfo( DToC( oDtp:GetDate() ) )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Date-Time Picker

#include "FiveWin.ch"

function Main()

   local oWnd, oDtp, tDateTime := DateTime()

   DEFINE WINDOW oWnd TITLE "DateTime Picker" SIZE 350, 200

   @ 40, 30 DTPICKER oDtp VAR tDateTime SIZE 180, 22 PIXEL OF oWnd ;
      PICTURE "dd/mm/yyyy HH:MM:SS"

   @ 100, 30 BUTTON "&Show" SIZE 80, 25 PIXEL OF oWnd ;
      ACTION MsgInfo( DToC( oDtp:GetDate() ), "Selected" )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

See Also