Formatting Dates In Formula LanguageSince we've been developing in Notes for many years, sometimes we forget that developers new to Notes may not know some of these things that we take for granted. Like taking a date field and displaying it in a "familiar" format. For example, we have gotten in the habit of showing all our dates, no matter what application, in WWW DD MMM YYYY format, as in Sun 01 Jan 2000. This is a format that everybody should understand, no matter what language they speak or what country they are from. If MM/DD/YYYY or DD/MM/YYYY is used, confusion can appear (03/04/2000 could be seen as April 3rd or March 4th, depending on your nationality). To show a date field in WWW DD MMM YYYY format, use this formula:
@Select(@Weekday(<YourDateField>); "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat") + " " + @Right("0" + @Text(@Day(<YourDateField>)); 2) + " " + @Select(@Month(<YourDateField>); "Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec") + " " + @Text(@Year(<YourDateField>))
Obviously, if you don't want the weekday to appear, you can just eliminate the first part of the formula.
The only caveat with this method is working with multiple values. Although formulas like @Text, @Weekday, @Month, @Day, and @Year work with lists (they apply to every entry in the list and return a list), @Select does not apply to each entry of the list. It applied to the first member of the list and then that first member of the list is duplicated throughout the list. So if you use the formula above on a list, the text weekday and text month will be those of the first date in the list.
But, wait, there's more! If you DO want to do all the members of a list of dates, @Transform can do this for you in a jiffy. Here's the formula:
List := @Transform(<YourDateListField>; "x"; @Select(@Weekday(x); "Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat") + " " + @Right("0" + @Text(@Day(x)); 2) + " " + @Select(@Month(x); "Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec") + " " + @Text(@Year(x)));
@Implode(List; ", ")
In this instance, the @Transform function runs on every element of the date list. For each element, the value is stored in a local variable called "x". Then I use the same formula as earlier, only this time on "x". The value is added to a temporary list. At the end, the variable List has a converted value for each date in the date list. I then implode those to one long string with a comma as a separator. If I was doing this in a multi-value text field, I could simply return List as the result of the formula and let the field properties determine how the multiple values will display.