When formatting dates in PowerShell with a custom format such as `yyyy-MM-dd`, is the output guaranteed to be consistent across different systems? This example formats the same date with every culture installed on the machine, compares each result with the invariant-culture version, and groups cultures that produce different strings. For example, Thai uses a Buddhist calendar and can return a year such as `2569` instead of `2026`, while several Persian-related cultures and Arabic (Saudi Arabia) can use different calendar systems. The goal is to show when explicitly specifying `InvariantCulture` matters, especially when generating values for logs, filenames, comparisons, or data exchange.
3 Answers
One important correction: passing `$null` does not select the invariant culture. For `DateTime.ToString`, a null format provider falls back to `CurrentCulture`, so it can still produce culture-dependent results. Use `[CultureInfo]::InvariantCulture` when consistent formatting is required.
This is also a reason to be cautious with `Get-Date -Format`: it formats using the current culture but does not provide a direct way to pass a culture provider. If the exact output matters, format the DateTime object yourself with `ToString()` and an explicit culture.
The main point is that converting a DateTime to a string uses the current culture unless you specify otherwise. A format like `yyyy-MM` can therefore produce different results depending on the machine's culture and calendar. For example, a Thai culture can format the year as `2569` rather than `2026`. For culture-independent output, pass `[CultureInfo]::InvariantCulture` explicitly: `(Get-Date).ToString('yyyy-MM', [CultureInfo]::InvariantCulture)`. Whether you want invariant or localized output depends on the purpose—data exchanged between systems should usually be invariant, while user-facing dates may need the user's culture.
The same issue applies to separators. A slash in a custom date format can be replaced by the culture's date separator, so a German culture may turn `yyyy/MM` into something using dots. Escape or quote the separator when you need it to remain literal.

So these are effectively equivalent when the current culture is Thai: calling `ToString('yyyy-MM')`, passing `[CultureInfo]::CurrentCulture`, and passing `$null`—all can produce the Buddhist-calendar year.