alex at tweedly.net
Sat Jul 15 09:41:07 EDT 2023
On 14/07/2023 19:45, Bob Sneidar via use-livecode wrote:
> Because I’m not that good with regular expressions and the format function. :-) But you example has one too many close parens.
Oops - I got caught out copying / pasting again :-(
Yes, of course it should have been
> put format("%s-%02d-%02d", item 1 of theDate, item 2 of theDate, \
> item 3 of theDate) into theDate
> Also, for SQL Date I do not thing UK or US matters. It’s YYYY-MM-DD everywhere, isn’t it?
Yes, sql (or ISO) is same everywhere.
> Also, I assumed that the localization of the LC engine would take into account the local date format for the built in date functions. Is that incorrect?
That is correct, but there is kind of a problem (or at least limitation)
with the function.
If I have a user here (UK) type a date into a field, and then I try to
format it to SQLdate (or anything else) using this function, it will
fail. My user will type something (15/07/2023), and that gets an
"invalid date" error.
I'm not sure there is anything you can do that is completely safe - you
can't tell whether a /-separated date string is US or UK. But I'd argue
that dates ready to pass in to the function are either
internally-generated (so they'll be sql, or dateitems, or otherwise
unambiguous), or they are user-generated (and hence local format). And
therefore I would suggest changing the code to
> put item 2 of theDate & "/" & \
> item 3 of theDate & "/" & \
> item 1 of theDate into theDate
> convert theDate to dateitems
> convert theDate from system date to dateitems
> END IF
> -- replace "." with "/" in theDate
> -- convert theDate to dateitems
More information about the use-livecode