How to apply a Custom Date Format to a Date/Time datatype field

I support the design template for a database that is used globally. Groups download the template and apply it to their own instance of the database.

Since this is used gloabally I need to give the DBA the option to select the date format to use throughout the database for consistancy.

In the database Profile Document I give them a radio button field to select the format they want (ie. mm/dd/yyyy, dd/mm/yyyy or yyyy/mm/dd)

My code gets the format from the Profile Document.

In Options: Use “DBDateFormat”

'---------------------------------------------

'set dates to the Profile Document format selected

Dim db_dateformat As String

Dim db_dateonly As String

Dim db_datetime As String

Dim db_dt As Variant

Dim db_dteonly As Variant	

db_dateonly = DBDateFormat( db_dateformat )

db_datetime = db_dateonly+" hh:mm:ss"

db_dt	    = Format(Now, db_datetime)

db_dteonly  = Format(Now, db_dateonly)

'--------------------------------------------

This works fine for date/time stamping text strings (logging info and such) But when I try to apply the selected format to a field of Date/Time datatype, it converts it to Text datatype.

I’ve tried:

Set tmptime=New NotesDateTime(db_dteonly)

but it still ends up as a Text datatype.

The date/time fields have to be “Date/Time” datatype because they’re used to control the execution of revalidation and QEVs and have to be used with Adjust methods:

Call RemindDate.AdjustDay( 7 )

How can I apply the date format selected in the Profile Document to date fields of Date/Time datatype and retain the Date/Time datatype?

Your help will be greatly appreciated. Thank You

Subject: format

have computed for display fields for the custom formatted dates because you cant touch the values of the actual date/time fields themselves without changing them (as you figured out).

either that or stick to a date format that is globally unambiguous, eg 03-JAN-2010

Subject: Formatting dates – don’t be bossy

You do not need a control to adjust the formatting so that all users of the application see the same thing. Just use date fields, and let the users’ workstations display dates according to each user’s preferences. Consistency is overrated. Avoiding confusing people by displaying dates in a format they’re not used to, is much more important.

If you’re careful not to store dates as text, all will be well. As Graham says, formatting is not stored along with the date.

Subject: How to apply a Custom Date Format to a Date/Time datatype field

It’s not a matter of being ‘bossy’ or ‘Consistency being overrated’, it’s what the customer has requested. They want to be able to apply a single format throughout the database.

Setting ‘User Preferences’ at the field level isn’t an option since its used in multiple geographies. We don’t what to have to customize the template by country.

Graham, thanks for your input.

Subject: Date’s do not have any formatting …

Date/Times are stored in the Notes database a pure numbers. They have no formatting what-so-ever.

When a date is displayed to the user, through a form field or a view, it’s formatted for display based on the setting of the Field or Column.

In order to do what you specify, I’d suggest …

When date need to be only displayed in forms, you convert them to text using the Format function in a Computed for Display field.

When they need to be edited, use a date field, with the format set to “Use preferences from user setting”, and include a display field next to the entry box that will display the formatted date as above.

Views … not sure what you can do here. For columns that don’t need to be sorted, use Formatted text. If they need to be sorted, you’re limited to using the “User settings” preference.