Date Format Exception again

Hello guys,

Apparently i run into this error again after years

Continuing the discussion from unsupportedformatexception in Xojo:

So i have the date recovered from an XML which is the following string


i have the code

Var bDate As DateTime

bDate = DateTime.FromString(birthDate)

where it fails with the RuntimeException

Parse error: date needs to be in the format of YYYY-MM-DD HH:MM or YYYY-MM-DD

Any idea what could be the error ? as i don’t get it .


MacOS Ventura 13.6.4
M1 Mac
XOJO 2023 R4

The error is (most likely) that at that date there is no DateTime with Time 00:00:00 for your locale.


Var bDate As DateTime

bDate = DateTime.FromString(birthDate + " 03:30")

and see if that helps.

Unlikely, because:

When no locale is specified, the dateValue parameter can be in either SQLDate (YYYY-MM-DD) or SQLDateTime (YYYY-MM-DD HH:MM:SS) formats.

Source: DateTime — Xojo documentation

Your code looks good. Maybe there are “hidden” chars in your Date String?
But it should throw a Parse Error if the Date Format would be the issue. Or?

1 Like

I’m talking about this Issue:
There are some parts of the world that Daylight time changes at midnight so no DateTime with 00:00:00, this may be the case for OP (we need to know the locale).

Is like trying to do this in the USA (well for all parts that the DST starts in March 10, 2024):

Var bDate As DateTime

bDate = DateTime.FromString("2024-03-10 02:00")

you get this in Xojo:

if we change 02:00 to 03:00 then there is no problem as 03:00 exists.

1 Like

Thank you. I did not know about this. :slight_smile:

1 Like

What timezone/region are you using?
According to: Daylight Saving Time Around the World 1979
there are 4 places that changed the clock during 1979-05-27 and all from 00:00 to 01:00 so your code will report an error there by not putting a time to the .FromString.

Hi Alberto, GMT +1 and GMT +2

Is it actually defined that 02:00 doesn’t exist and 03:00 exists (and not the other way around)?

What does it show?

MessageBox TimeZone.Current.Abbreviation + " = " + TimeZone.Current.SecondsFromGMT.ToString

1 Like

As it moves forward (March this year for my TZ) by one hour, 2:00 doesn’t exist (nor any minute of that hour) only 3:00 and later.

If you ask if defined by an international commission or something like that, I don’t know.

I’m sorry but what I’m looking for is if you are in Italy, or other TZ that change to DST 1979-05-27, so we know that is why you get the error.

Did you try adding " 03:00" to the birthDate? Do you get an error?

Can you run the code Rick posted?

Precisely, I asked whether we are allowed to consider that 1:59 and 2:00 exist, 2:01 up to 3:00 don’t, and 3:01 exists, instead of saying 1:59 exists, 2:00 up to 2:59 don’t and 3:00 exists. It may sound a “silly” question, but I like to explore beyond our habits.
Well, I guess it’s defined strictly.

I only know that for Xojo 2:00 up to 2:59 (including seconds, my guess not tested) doesn’t exist (for USA clock forward day).

When I used Tivo, the guide didn’t show 2 am shows, so I had to program at 3:00 am. Shows of 2 hrs that started at 1:00 ended at 4:00.

I have never been awake when the clock forward happens, but I guess the phones will show 1:59 then 3:00 instead of 2:00.

And for the clock back we have double 2:00 up to 2:59 and not easy way for DateTime.FromString (using SQLDateTime) to set it to the first or the second 2:xx

Fun with dates.

1 Like

hi back , traveling so i will be able to test in few days , the issue and the problem here is that Date should not be affected by time or else keep separate the date and the datetime format as in my case i get a birth date in the sql format and while i understand that when you do input the data as new , but when you get it , the first rule of data processing is not to alter the data in any way , now you are asking to put 03:00 and other tests while for the sake of testing i will do but i will not alter data just that because Xojo does not know how to handle a date .

it’s like i’m born in eu but because i input the data in US i was born one day earlier or late . those should be as they come and specially for dates not to change them based of GMT in some cases .

I convert all dates that I receive, into SecondsSince1970. That is then what I store in an SQLite database.The date will have a timestamp and a timezone too, so it’s not ambiguous. The trouble with your 2024-02-02 17:02:30 format is that it has no timezone and is hence completely ambiguous.

My timestamps then convert nicely back to a human readable form, with that form chosen by the user.

1 Like

I understand your problem. We are just asking more information/tests to see if the problem is what Xojo already have on Issues (see above for case numbers).

In Xojo DateTime, even if you don’t define the hour, has an hour component. The problem is that if the hour component doesn’t exist Xojo shows the error you see.

Maybe Xojo can fix the problem or maybe they can add something like a DateTimeOnlyDate feature for cases that handling the hour could cause problems.

Indeed. Thanks for your reply.

Exactly. It’s even outlined by the name of the class: DateTime.

I’d like to point out the obvious: even outside of programming, in real life, there are invalid dates. For example, 29th of February 2023, 35th of June 2023, or, in countries with daylight saving time, 24th of March 2024 at 2:30 (at this day, since the clock jumps from 2:00 to 3:00, there’s no 2:30).
These dates are invalid in real life so it’s expected that the computer won’t understand them. What DateTime would you expect to get if you pass “2023-02-29” (even without talking about the time part)?

Thank you for this, I remember when I used Date instead of DateTime that Date is forgiving about invalid input. I did a test and maybe OP may want to try to use Date instead of DateTime until Xojo either a) changes DateTime in some way (to at least work with invalid dates in the range of DST) or b) adds DateTimeOnlyDate option.

This works with Date:

var onlydate as new date
onlydate.SQLDate = "2024-02-30"

as this year February has 29 days the result for Date is:
March 1, 2024

I understand Date is deprecated buy I hope Xojo does not remove it in the future.

1 Like