Returns or sets a value that specifies the format used by the control when displaying date/time information.
Syntax
object.CustomFormat [= string]
The CustomFormat property syntax has these parts:
Part | Description |
object | An object expression that evaluates to an object in the Applies To list. |
string | A string expression specifying the format of the display. |
Settings
The DateTimePicker control supports the following format characters:
String Fragment | Description |
d | The one- or two-digit day. |
dd | The two-digit day. Single digit day values are preceded by a zero. |
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 a zero. |
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 a zero. |
m | The one- or two-digit minute. |
mm | The two-digit minute. Single digit values are preceded by a zero. |
M | The one- or two-digit month number. |
MM | The two-digit month number. Single digit values are preceded by a zero. |
MMM | The three-character month abbreviation. |
MMMM | The full month name. |
s | The one- or two- digit seconds. |
ss | The two-digit seconds. Single digit values are proceeded by a zero. |
t | The one-letter AM/PM abbreviation (that is, "AM" is displayed as "A"). |
tt | The two-letter AM/PM abbreviation (that is, "AM" is displayed as "AM"). |
X | A callback field. The control still uses the other valid format characters, and queries the owner to fill in the "X" portion. The owner must be ready to respond to events that request information about how to fill in these fields. Multiple 'X' characters can be used in series to signify unique callback fields. |
y | The one-digit year (that is, 1997 would be displayed as "7"). |
yy | The last two digits of the year (that is, 1997 would be displayed as "97"). |
yyy | The full year (that is, 1997 would be displayed as "1997"). |
Remarks
The CustomFormat property acts as an input mask. To display a custom format, the Format property must be set to dtpCustom
You can add body text to the format string. For example, if you want the control to display the current date with the format "Today is:Friday July 25, 1997 Time: 8:34 AM", the CustomFormat string is "'Today is:' ddddMMMMdd, yyy ' Time: 'h:mtt"
. Body text must be enclosed in single quotation marks.
One of the custom format fields described above is a callback field. A callback field allows you to customize output by specifying certain parts of a format string as callback fields. To declare a callback field, you must include one or more 'X' characters (ASCII Code 88) anywhere in the body of the format string. Callback fields are displayed in left-to-right order.
When a new date is displayed in a format that includes one or more callback fields, the Format and FormatSize events are raised for each callback field. You can use the Format event to specify a custom response string, and the FormatSize event to determine the space needed to display the string. This behavior gives you complete control of how a callback field is displayed.
Each sequence of X's has a specific meaning. For example, X might mean "st/nd/rd/th" (for "1st" "2nd" "3rd" or "4th") and "XX" may mean "first" "second" "third" or "fourth". These fields do not format the user's text. They format the date into a displayable format.
For example, let's say you want to display the month in Spanish as well as English in a format like this:
July (Julio) 29
You would create a format string that looked like this:
MMMM XXXX d
When processing the Format and FormatSize events, you can check which callback field is being called by comparing the input format sting with "XXXX". If the field string matches, an output string "(Julio)" can be built and the length of the output string can be supplied.
The number of Xs is only used by an application to determine what text to supply for a callback field. When processing the FormatSize event, the size of the text can be programmatically calculated.
You can create unique callback fields by repeating the "X" character. Thus, the format string "XXddddMMMdd', 'yyyXXX" contains two callback fields. Callback fields are treated as valid fields, so the application must be prepared to handle Key events.