« [Tip] Using graphics in table column headers | Main | [Tip] Table row height controls »

May 02, 2008

[Tip] AM/PM times

by David Workman
Data Mosaic

You have to do a little work to store and display time data so that it is user friendly. AM/PM display is the most common time format here in the U.S. And displaying seconds is most often overkill -- sometimes 30 minute intervals is the most granularity a user needs.

Picture_26

Time type

You can specify a time field in the back end database as a "datetime" type just like you would a date field. Then use Servoy's field format property to just display the time part. If you want to get fancy, each database vendor has various type options for dates and times that you can explore.

AM/PM format

The format string for am/pm time is: "h:mm a". To use in a method (as a field assignment or to search with), use the date format function like this:

Data entry (default)

You can sort of use the calendar field type for data entry but it is clunky. In order to make it work, the field format string needs to be "hh:mm a". The clunky part is that you can't set am/pm except by using 24 hour times. Also, the AM or PM tag doesn't update in the popup calendar until you open it again.

Picture_27

Data entry (roll your own)

People don't like typing in numbers. Buttons to move the time value up and down is generally preferable. The following code will work with any time field as long as you use the following naming conventions (in this case set the field type to text_field):

  • field: does not need to be named
  • up button: [field_name]_up
  • down button: [field_name]_down

Code to move time up or down by 30 minutes. Adjust to your time increment:

| Posted by David Workman on May 2, 2008 at 06:36 PM in Tips | Permalink

Comments

Post a comment