Developing for Dynamics GP

by David Musgrave (Perth, WA, Australia) and the Microsoft Dynamics GP Developer Support Team (Fargo, ND, USA)

Displaying Dates in any format on Reports

Displaying Dates in any format on Reports

  • Comments 4

David Meego - Click for blog homepageOver the years, I have seen a huge amount of effort and multiple calculated fields to format a date field on a report into a desired format that is something other than the default short date format, usually DD/MM/YYYY or MM/DD/YYYY depending on country (as defined in the control panel).

While you have to admire the efforts that people will go to to get a date displayed in a desired format, it frustrates me that so much effort goes into something that could be so quickly and easily achieved with the RW_DateToString() user defined Report Writer (RW) function.

The RW_DateToString() function is one of a suite of functions that I developed back in 2002 and got added to the core Dynamics.dic application dictionary for versions 7.0 onwards. For details on the other RW functions added, see the post on this blog in the more information section below.

To use the RW_DateToString() function, follow the steps below: 

  1. Create a string calculated field
  2. Select the Functions Tab
  3. Select User-Defined
  4. Select Core: System
  5. Select Function: RW_DateToString
  6. Click Add 
  7. Select the Fields tab
  8. Locate the date field you want displayed
  9. Click Add
  10. Select the Constants tab
  11. Select Type: String
  12. Enter the Constant as the desired date format template (see below)
  13. Click Add
  14. Click OK

The final Calculated Expression should be something like:

FUNCTION_SCRIPT(  RW_DateToString  Date  "mmmm DD, YYYY"  )

For example:

For today's date the format string "mmmm DD, YYYY" will produce "August 16, 2010".

The date format template string is a string constant which describes to the RW_DateToString() function how to display the date.  Any text can be contained in the string and the following placeholder characters will be substituted with the appropriate:

Placeholder Characters  Date Component Format 
ddd day of week as 3 letters
dddd day of week in full
day of year
NN  day of year (padded)
day of month
DD  day of month (padded)
month of year
MM  month of year (padded)
mmm  month of year as 3 letters
mmmm  month of year in full
YY  year of date (2 digits)
YYYY  year of date (4 digits)

Note: If you want to change the language of the days of the week or the months of the year, please use the Modifier to change Message Resources IDs 12201 onwards and 18618 onwards respectively. These messages are used elsewhere in the application, so changing them here will affect more than just the RW_DateToString() function.

For more information see the posts below:

I hope this saves you lots of time. Enjoy.

David

Page 1 of 1 (4 items)
Comments Information

PLEASE READ BEFORE POSTING

Please only post comments relating to the topic of this page.

If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.

Leave a Comment
  • Please add 5 and 3 and type the answer here:
  • Post