JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Setting Date-Time Picker Custom Formats

You can set the format for the dates and times displayed in date-time pickers customizing that format as you like; for example, you can display (and so let the user set by editing) just dates, or just times, or both. To set a custom format, you set the date-time control's Format property to DateTimePickerFormat.Custom, then you assign a custom format string to the CustomFormat property.

You create a custom format string using these items:

  • d— The one or two-digit day.

  • dd— The two-digit day. Note that single-digit day values are preceded by a zero.

  • ddd— The three-character day-of-week abbreviation.

  • dddd— The full day-of-week name.

  • h— The one- or two-digit hour in 12-hour format.

  • hh— The two-digit hour in 12-hour format. Note that 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. Note that single-digit values are preceded by a zero.

  • m— The one- or two-digit minute.

  • mm— The two-digit minute. Note that single-digit values are preceded by a zero.

  • M— The one- or two-digit month number.

  • MM— The two-digit month number. Note that 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. Note that single-digit values are preceded by a zero.

  • t— The one-letter AM/PM abbreviation ("AM" is displayed as "A").

  • tt— The two-letter AM/PM abbreviation ("AM" is displayed as "AM").

  • y— The one-digit year (2002 is displayed as "2").

  • yy— The last two digits of the year (2002 is displayed as "02").

  • yyyy— The full year (2002 is displayed as "2002").

To display literals, such as: or /, you must escape them by surrounding them in single quotes. For example, to display the date and time in the format 12/01/2002 12:00 PM, the CustomFormat property should be set to MM'/'dd'/'yyyy hh':'mm tt.

Here's another example; in this case, I'm creating the display you see in Figure 8.14 in the date-time picker at the top of the form. This will display dates and times in the format "September 27 12:00:00 PM":

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    DateTimePicker1.Format = DateTimePickerFormat.Custom
    DateTimePicker1.CustomFormat = "MMMM dd hh:mm:ss tt"
End Sub
Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor