I’m using the following bricks for this scenario…
PixieBrix Session Reader → getting @session.timestamp
Parse Date → Input ( @session.timestamp )
→ Output ( @parsedDate.local.date )
My output for Parse Date is usually having MM/dd/yyyy format but for 1 user its having an output of dd/MM/yyyy? is the format output dependent on the system date format?
Do you have any brick/approach to force the output as MM/dd/yyyy regardless of the system date format?
Hi @ryan.m, thanks for the question!
The timestamp from the session reader is in ISO 8601 - Wikipedia, so will always have the order YYYY-MM-DD
For the Parse Date brick, the
Unfortunately, there isn’t a a way to detect what the user’s locale setting is to know if you need to swap the order. Therefore, you’d need to use the
I will open up a ticket here to provide a locale argument the parse date brick: Provide locale argument to parse date brick · Issue #3690 · pixiebrix/pixiebrix-extension · GitHub
If you need to get a consistent order, you can transform the ISO date using the JQ brick (using regular expressions). Here’s an example: jq play
Let us know if that works for your use case!
I tried using the JQ Brick with the regex you provided.
However my concern with the provided expression is below…
- out of x number of users only few people are having their browser date format as dd/mm/yyyy
- with the expression provided. people with dd/mm/yyyy format will have the mm/dd/yyyy format. (correct/desired)
- however, those people (majority) with desired browser date format of mm/dd/yyyy, after using the expression will be changed to dd/mm/yyyy.
Im testing this out by changing my chrome’s language to English ( UK ) for me to have dd/mm/yyyy format, then revert to English ( US ) to return to mm/dd/yyyy.
@ryan.m For your use case, what you’ll want to do is use the ISO 8601 formatted date which is an international standard which will always start with YYYY-MM-DD.
In the parsed date brick, that will be on:
The regular expression you need to use will be slightly different: jq play, using the
- to match the hyphens in the date and with the correct ordering in the
.date | capture("(?<year>\\d+)-(?<month>\\d+)-(?<day>\\d+)") | [.day, .month, .year] | join("/")
Let us know if this helps!