Author Topic: HOW TO show dates using a custom format  (Read 1778 times)

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2852
    • View Profile
    • Codecore Technologies
HOW TO show dates using a custom format
« on: July 01, 2010, 07:53:45 am »
Many drivers expose date/time values which can be shown on a touch screen interface. This is usually done using a macro in a label control.

For example the Weather Channel driver exposes a list of dates for it's forecast. In the example macro below, since the Weather Channel Dates property is a list of date (ie, an array) it includes an index of which date to show... we will show the date at index 0:

{ weather.Dates[0] }

The above example macro can be automatically generated using the 'Insert Macro' button in the control's Text property pane. The macro chooser does not currently support formatting but it is planned for the future. So the date will be show using the system default format.

If you want to use a custom format you can manually modify the macro by adding the ToString(...) method to the end.

To just show the abbreviated day of the week such as 'Wed' you would use:
{ weather.Dates[0].ToString("ddd") }

To show the date using the systems short date format (such as  6/15/2009) you would  use:
{ weather.Dates[0].ToString("d") }

To display 'Fri, Aug 29' you would use:
{ weather.Dates[0].ToString("ddd, MMM d") }
 
For a list of all the formatting options please see:

- Standard  Date and Time Formats
- Custom  Date and Time Formats
« Last Edit: July 01, 2010, 07:55:43 am by John Hughes »
John Hughes
Codecore Technologies