Date format: Year and Month

How can I format a DateTime Object with year and month with local language. Expected result: “May, 2023” (us, uk) or “Mai 2023” (German, French)

This is my temporary solution

Var s As String = value.ToString(Locale.Current, DateTime.FormatStyles.Full,  DateTime.FormatStyles.None).Titlecase
Var c() As String = s.Split
TitleLabel.Text = c(2) + " " + c(3)

Can I create my own format like “MMM, yyyy” or something like that?

Is there a way to retrieve textual month (with local name)?

Use ToString and define the format you need.

From the documentation:
https://documentation.xojo.com/api/data_types/datetime.html#datetime-tostring

The format parameter is expected to be ICU Date/Time Format

Don’t pay attention to:

For example, mm-dd-yy for the date and hh:mm:ss for the time, or mm-dd-yy hh:mm:ss for both. The format string is case-sensitive.

as there is a documentation error, it should be MM-dd-yy and not mm-dd-yy as mm are minutes.
#72333 - Documentation for DateTime.ToString gives examples with mistakes


Yes, this works:

d.ToString("MMM, yyyy")
1 Like

My solution

// Title
TitleLabel.Text = value.ToString("MMMM YYYY", Locale.Current).Titlecase

“MMMM YYYY” can be store in a localized constant with “YYYY, MMMM” for English