Skip to main content

Text Formatting

@DateTime I format <valueRef> from "<source-format>" to "<target-format>" as <name>

Converts the given date/time value to another format and stores the result in the given name in the global scope.

Where

    <valueRef> is the name of the binding containing the source date/time value

    • Can be the name of any binding that contains or resolves to a date/time value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • <source-format> is the source date time format pattern to convert from
  • <source-format> is the target date time format pattern to convert to
  • <name> is the name to bind the formatted date/time value to

Example

  Given ISO date is "2026-03-14"
When @DateTime I format ISO date from "yyyy-MM-dd" to "dd/MM/yyyy" as dmy date
Then dmy date should be "14/03/2026"

Since v4.18.1, Gwen also supports ordinal suffixes (1st, 2nd, 3rd, 4th, etc..)

  Given ISO date is "2026-03-02"
When @DateTime I format ISO date from "yyyy-MM-dd" to "d(st|nd|rd|th) MMMM yyyy" as display date
Then display date should be "2nd March 2026"

And (converting the other way)

Given display date is "23rd March 2026"
When @DateTime I format display date from "d(st|nd|rd|th) MMMM yyyy" to "yyyy-MM-dd" as ISO date
Then ISO date should be "2026-03-23"
@Number I format <valueRef> from "<source-format>" to "<target-format>" as <name>

Converts the given numeric value to another format and stores the result in the given name in the global scope.

Where

    <valueRef> is the name of the binding containing the source numeric value

    • Can be the name of any binding that contains or resolves to a numeric value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • <source-format> is the source decimal number format pattern to convert from
  • <source-format> is the target decimal number format pattern to convert to
  • <name> is the name to bind the formatted numeric value to

Example

  Given number is "1234"
When @Number I format number from "#" to "$#,##0.00" as dollars
Then dollars should be "$1,234.00"

Since v4.18.1, Gwen also supports ordinal suffixes (1st, 2nd, 3rd, 4th, etc..)

  Given number is "22"
When @Number I format number from "#" to "#(st|nd|rd|th)" as ordingal number
Then ordingal number should be "22nd"

And (converting the other way)

Given ordingal number is "1st"
When @Number I format ordingal number from "#(st|nd|rd|th)" to "00" as leading zero number
Then leading zero number should be "01"