CustomFormat

Applies to

DatePicker controls

Description

The CustomFormat property specifies a custom format for the display of the date in a DatePicker control. You must set the Format property to the enumerated value dtfCustom! for the CustomFormat to take effect.

The format strings in the following table can be combined to format the date and time. If you want to include string literals in the CustomFormat string, enclose them in single quotes to ensure that the letters they contain are not interpreted as format strings.

Format string

Description

d

The one- or two-digit day.

dd

The two-digit day. Single-digit day values are preceded by 0.

ddd

The three-character weekday abbreviation.

dddd

The full weekday name.

h

The one- or two-digit hour in 12-hour format.

hh

The two-digit hour in 12-hour format. Single-digit values are preceded by 0.

H

The one- or two-digit hour in 24-hour format.

HH

The two-digit hour in 24-hour format. Single-digit values are preceded by 0.

m

The one- or two-digit minute.

mm

The two-digit minute. Single-digit values are preceded by 0.

M

The one- or two-digit month.

MM

The two-digit month. Single-digit values are preceded by 0.

MMM

The three-character month abbreviation.

MMMM

The full month name.

s

The one- or two-digit second.

ss

The two-digit second. Single-digit values are preceded by 0.

t

The one-letter abbreviation for AM or PM in uppercase (AM displays as A).

tt

AM or PM in uppercase.

X

A callback field used to query the user for a portion of the custom format. This format string is not supported in PowerBuilder.

y

The one-digit year (2007 displays as “7”).

yy

The two-digit year (2007 displays as “07”).

yyy or yyyy

The full year (2007 displays as “2007”).

Usage


In the painter

StepsTo set the CustomFormat property:

  1. Select dtfcustom! from the Format drop-down list on the General page of the control’s Properties view.

  2. Specify a custom format in the Custom Format field.

    This custom format displays the date and time at 8 p.m. on the first day of 2007 as January 1, 2007 08:00:00 PM:

    MMMM d, yyyy hh:mm:ss tt
    

    This custom format displays the same time on the last day of 2006 as December 31, 2007 20:00:00 PM:

    MMMM d, yyyy HH:mm:ss
    


In scripts

The CustomFormat property takes a string value. The following statements set the Format property to allow a custom format, then set the custom format to display the full month name, the two-digit date followed by a comma, and the full year:

dp_1.Format = dtfCustom!
dp_1.CustomFormat = "MMMM dd, yyyy"