How do I display dates with 4 digit year using Locale

Currently, I am using the .shortDate value but that shows up as a 2 digit year. .LongDate shows the 4 digit year but everything is too long. I could format to a certain format using string but it will not comply to the locale settings.

Is there a way to format the date year to a 4 digit year and yet keep the locale settings ?

Thanks.

You can always create the format you want using date.year, date.month and date.day together with format or str.

using old framework :

[code]Public Function ShortDateWithLongYear(extends aDate as Date) as String
dim res as string

res = aDate.ShortDate
res = NthField( res,"/",1)+"/"+NthField( res,"/",2)+"/"+str(aDate.Year)

Return res

End Function
[/code]

Thanks. It will work except that some countries Year is in the front.

I might have found a solution using this

[code]dim td,localeformat as string

localeformat = nslocalembs.currentlocale.dateshort.dateformat
td = localeformat
td = Replace(td,"m",str(d.month))
td = Replace(td,"d",str(d.day))
td = Replace(td,"yy",str(d.year))[/code]

your solution works only if mbs plugins is installed … :wink:

that’s true. I just couldn’t find any way around it. It would have been so much easier if the world follows one date format or at least placed the year at the back.

in fact, it is the user responsability to select 4 digits instead of 2 in the system preference panel.
I have an abbreviated date that outputs 4 digits on my system…

ShortDate la franaise on a US system :

[code] dim d as xojo.Core.Date = Xojo.Core.Date.Now

Dim myLocale As New Xojo.Core.Locale(“fr-FR”)

Dim t As Text = d.ToText(myLocale,Xojo.Core. Date.FormatStyles.Short, Xojo.Core.Date.FormatStyles.None)

msgbox t[/code]

Result : 18/09/2016

To keep the system settings, use Locale.current

But indeed there is something when I do that with en-US, it shows the year in two digits, although my PC system preferences short date is set specifically to M/d/yyyy. Could be a bug in xojo.core.date.

Michel, it depends on how the user defines a “short” date in the system preferences.
if the user choose 2 digits, then the locale short date will return 16 and not 2016.

[quote=287498:@Jean-Yves Pochez]Michel, it depends on how the user defines a “short” date in the system preferences.
if the user choose 2 digits, then the locale short date will return 16 and not 2016.[/quote]

Precisely not with Xojo.Core.Date in the example above for Locale.Current on a US system . Why I think it is a Xojo bug.