How to make date "1990-03-03" (string) display day and month with zeros in fields?


Currently this is what’s being displayed, without zero, making the dropdown month dysfunctional:

Will share my findings after all:

The RegEx for that is ^(\d)$ to which you need to add a \ for proper integration into the formula, like so:

REPLACE_ONE_REGEX(STRING(GET_DATETIME_COMPONENT(current.dob, "date")), "^(\\d)$", "0"+GET_DATETIME_COMPONENT(current.dob, "date"))

Make sure the RegEx is between double (or single) quotes.

1 Like

Correct, and with your permission, I’ll explain a little for the newer ones an example about your code:

The example and solution provided by our friend @Fred_Kuzyk is a code fragment that uses a regular expression (RegEx) to modify a date (Example: birthday) stored in a variable called “current.dob”. The regular expression itself is “^(\d)$” and is used along with the REPLACE_ONE_REGEX function to replace any single digit found at the beginning of the string with a zero plus that digit.

The regular expression “^(\d)$” is used to find a single digit that is at the beginning and end of the string. The symbol “^” is used to indicate the beginning of the string and the symbol “$” is used to indicate the end of the string. The parentheses surrounding “\d” are used to capture the digit and allow for its use later in the substitution. The “\d” refers to any decimal digit and the “+” added in front of it indicates that a zero should be added in front of the captured digit.

The REPLACE_ONE_REGEX function is used to replace a single occurrence of the regular expression in a given string with a given replacement string. In this case, the replacement string is “0”+GET_DATETIME_COMPONENT(current.dob, “date”), which means that a zero will be added in front of the day of the birthday stored in the “current.dob” variable.

What @Fred_Kuzyk says is true: It is important to make sure the regular expression is between double or single quotes so that it is interpreted correctly.

Thank you very much @Fred_Kuzyk

1 Like

Thank you for taking the time for this thorough explanation.

1 Like