Good Way to get the Date Format

Not in iOS, I need to have blank date fields with the correct format/mask for the location. I had no problems creating that mask for numbers using Einhugur’s CurrencyFormatter class which returns the local currency symbol, decimal symbol, thousands separator, place and symbol for negative numbers, etc. It works great.

I’m aware that the “/” is interpreted by XOJO to be the universal date element separator. However it’s important to know the order of numbers the local uses. US: month/day/year; Other: year/month/day; Other: day/month/year.

Anyone know how that information can be retrieved?

[quote=167423:@Gary McGuire]Not in iOS, I need to have blank date fields with the correct format/mask for the location. I had no problems creating that mask for numbers using Einhugur’s CurrencyFormatter class which returns the local currency symbol, decimal symbol, thousands separator, place and symbol for negative numbers, etc. It works great.

I’m aware that the “/” is interpreted by XOJO to be the universal date element separator. However it’s important to know the order of numbers the local uses. US: month/day/year; Other: year/month/day; Other: day/month/year.

Anyone know how that information can be retrieved?[/quote]

Xojo.core.date has the notion of locale in the ToText method that will produce the date for a particular region.

See http://developer.xojo.com/date

AFAIK Xojo.Core.Date has been available in desktop since 2014R3.

the day month year are always unambiguously numbers

so in theory you should be able to do something like (this is all written in the forum & 100% untested)

[quote] dim tmpDate as new date( 2256, 01, 30 ) // important that you set this so each component can be identified individually
dim tmpStr as string = tmpDate.ShortDate
// get the sep by replacing 2256, 56, 01, 1 and 30 IN THAT ORDER
dim sep as string = replaceall(tmpStr, “2256”, “”)
sep = replaceall(sep, “56”, “”)
sep = replaceall(sep, “01”, “”)
sep = replaceall(sep, “1”, “”)
sep = replaceall(sep, “30”, “”)
// whats left should be the separator(s)
// in theory you should have multiple (at least 2) but lord knows

// this DOES assume its one character
sep = left(sep, 1)

dim firstpart as string
dim secondpart as string
dim thirdpart as string

// now figure out the order
dim part() as string = REALbasic.split(tmpStr, sep)
// we should have 3 parts
if part(0) = “2256” then firstPart = “YYYY”
if part(0) = “56” then firstPart = “YY”
if part(0) = “1” then firstPart = “MM”
if part(0) = “01” then firstPart = “MM”
if part(0) = “30” then firstpart = “DD”

if part(1) = “2256” then secondpart = “YYYY”
if part(1) = “56” then secondpart = “YY”
if part(1) = “1” then secondpart = “MM”
if part(1) = “01” then secondpart = “MM”
if part(1) = “30” then secondpart = “DD”

if part(2) = “2256” then thirdpart = “YYYY”
if part(2) = “56” then thirdpart = “YY”
if part(2) = “1” then thirdpart = “MM”
if part(2) = “01” then thirdpart = “MM”
if part(2) = “30” then thirdpart = “DD”

[/quote]

Looks like a good idea, Norman. I’ll give it a try.

On iOS why not use the DatePicker
I know its been implemented via declares
Then you dont care about what format to enter dates as the picker handles that

(I just dont seem to be able to find the right forum post about it)

That, too, is a good idea. Are you talking about this one?

The issue with it is that I still want a TextField for displaying the date. Something like an employee’s DOB that would not default to Now and that a user might want to view but is unlikely to change.

Display it in the way the user specified using Xojo.Core.Date
That takes the users preference into account already

Ah, I see where we’re going wrong. I have to have it X-Platform including Win & Linux. It would be great if Locale could be expanded to include that info. In the meantime, I’m going to work on a function to return a mask for date using the code above.

Xojo.Core.Date IS x-platform as is Xojo.Core.Locale

The date picker isn’t - thats on iOS only

I knew Locale was, but on the Xojo.Core.Date I guess I confused Platform and Target.

Why does Xojo.Core.Date say “Target: All” but “Platform: Mac OS X, iPhone”?

Dunno - I’m not the documentation person :slight_smile:

The two things needed to get the date separator and order are necessary to localize dates in our code. While I have written 3 methods that borrow heavily from the code in this link, I have put in a feature request to simply add the date separator and date order to the locale information.

It is feedback case 38252, and I encourage you to join it.