ParseDate?

Big Sur 11.6
MacBook Pro M1 13"
Xojo 2015r1 project running under Xojo 2021r2.1.

The code below report a wrong date:


Bool = ParseDate("2021-11-08", Date_Start)
If Bool = False Then
  MsgBox "Date_Start holds a wrong date"
  Return
End If

Stupid !
(who is the stupid guy ?)


Bool = ParseDate("1 octobre 2021", Date_Start)

This works on my French OS.

OK, I will add lines to create a Date Object from the TextField and pass that… (if I can).

How are-you using a date typed by the user ?

It’s hard to tell what you mean, are you making a statement, or asking a question? Are you saying that it worked before or it worked in a different version of xojo/different version of mac os, or that it just doesn’t work?

http://documentation.xojo.com/api/deprecated/parsedate.html

ParseDate uses the current date formats that are specified in the regional/international system settings on the user’s computer. It recognizes those formats. For that reason, the specific formats that ParseDate will support on a particular computer cannot be specified. If you are having problems with a date format, check the International formats (macOS), Regional Settings (Windows), or equivalent feature on Linux to be sure that the format you are using is specified.

Well it looks like we posted at the same time and you have since found the problem and edited your 2nd post, so I’ll answer down here.

Usually you pass it through some sanity checks to make sure you have data in a readable format, if not you show an appropriate visual indicator (red *, message or whatever you decide).

You could try the new http://documentation.xojo.com/api/data_types/datetime.html#datetime-fromstring which will allow the YYYY-MM-DD format if no locale is specified. If that fails, try it with a locale specified to see if its in a “local format” then finally kick it back to the user to double check.

Failing all that you could go with a date picker which will stop the user from entering incorrect data.

1 Like

It was a question. (but can also be a rant on forced preferences).

Your answer is certainly right Julian.

my latests moves while you were writing your answers were:

  1. I use as test “1 octobre 2021” (French date locale) and ParseDate was working fine.
    [Sorry, I already stated that]

  2. My next move is to use (API 1):


Date_Start.Year  = CDbl(Left(TF_Date_Start.Text,4))
Date_Start.Month = CDbl(Mid(TF_Date_Start.Text,5,2))
Date_Start.Day   = CDbl(Right(TF_Date_Start.Text,2))

And this is working fine.

Nota: I also tried NthField(TF_Date_Start.Text, "-", 1) etc.

I always used ISO 8601 dates as user (or computer) passed dates. Using “locale” month names… to use in computer process data… No, thank you !