I have a string of a date which I want to parse into a datetime object. I have this:
$invoice = \'9 février 2017\'
[datetime]::parseexact($invoice, \'dd MMMM
The 3rd argument to DateTime.ParseExact is the IFormatProvider
, to which you can pass a CultureInfo instance in whose context the string should be interpreted, so you must pass it the object representing French culture:
[datetime]::ParseExact($invoice, 'd MMMM yyyy', [cultureinfo]::GetCultureInfo('fr-FR'))
Note that I've had to change dd
to d
, since your input string's day index only has a single digit.
By passing $null
as the 3rd argument, you're implicitly using the current culture, as reflected in [cultureinfo]::CurrentCulture
.[1]
[1] The automatic $PSCulture
variable works too, but only if the culture wasn't changed in-session.