I want a datetime from "2024-11-28"

Well, no one here uses yyyy-mm-dd either (nor have I ever heard anyone use week numbers, come to that). This is why I store date/times as seconds since 1970, nicely supported by the DateTime class. I let the user choose the display format they want, both for dates and times (12 or 24 hr for times). I suppose I could use the locale stuff but wrote the method to do all that display stuff quite early on.

It’s the standard “short” format here in Canada, for display purposes anyway.

But yes, storing a date time in SecondsFrom1970 is my preferred choice too, then I display based on the user’s localization.

Because I didn’t know the shortcut mask. Good finding.

1 Like

:+1:
And much of Asia too.
It was recommended we should all standardize on ISO 8601 in the wake of the millennium bug but you can lead a horse to the water…

1 Like

And who made the recommendation? A few geeks, I expect. It was also recommnded that we standardise on ISO networking protocols too.

I’m a volunteer technical assessor for a national standards accreditation authority. Being one of the few geeks who probably has to use this I find the US system confusing and unhelpful. Obviously at first sight 11/30/2024 is easy to understand, 12/01/2024 less so, and 12/01/24 even less. A lot of the world still uses the British format 30/11/2024 or 30/11/24. As Steve suggests there is an ISO Standard, (effectively UST) but the document costs real money - The only times that I see it is in computer applications, and scientific papers from China (where it is their standard). The IETF work-alike can be found here: https://www.ietf.org/rfc/rfc3339.txt with simple time zone offsets here: Time Zone Abbreviations - Worldwide List

It might be worth noting that the short form ISO date format is 20241130 without any delimiters, so that would be relatively easy to “build your own” with “String” Left, Middle and Right - Avoiding the need to specify the delimiter in “Split”. If you need times and timezones it gets more complicated with the short form: 20241130T040306Z

1 Like

Sorry, I should have added…
This often gets hard. Most of my applications have a database back end so I normally use a trigger when inserting, updating or deleting records. If I have a table called Users:-

CREATE TABLE "Users" (
	"ID"	INTEGER NOT NULL,
	"name"	TEXT NOT NULL DEFAULT 'test' UNIQUE,
	PRIMARY KEY("ID")
)

A SQLite example that fires when a user is deleted from my “Users” table inserts an audit record into a “UsersLog” table:-

CREATE TRIGGER “a_DeleteUsers” AFTER DELETE ON “Users” BEGIN INSERT INTO “UsersLog”(userID, name, deleted, DT) VALUES(OLD.ID, OLD.name, ‘1’, DATETIME(‘now’,‘localtime’)); END`

If you want UST remove the local time:-

`CREATE TRIGGER “a_DeleteUsers” AFTER DELETE ON “Users” BEGIN INSERT INTO “UsersLog”(userID, name, deleted, DT) VALUES(OLD.ID, OLD.name, ‘1’, DATETIME(‘now’)); END

It saves a lot of code, and fires irrespective of how the deletion is made. Most server databases like PostgreSQL have similar triggers.

UTC (AKA GMT)

Thanks Rick, I have no idea why I wrote that (Universal StandardTime). Possibly a combination of senility and drugs (no coffee, and post-operative medications)…

2 Likes

ezgif-6-c39b4a208e

1 Like

The use of ISO 8601 is mandatory in UK government IT systems now.

I’ve spent much of the last decade working on integrating systems and I’ve encountered numerous instances where organizations have invented their own codes for things that already have a recognized standard code defined for them.

It’s hardly a solely British format. European, possibly.

This affects 99.9% of the population not at all.

Anyway this is OT now, so I bow out.

No, its more British then European :wink: The typical european format is 30.11.2024

That was an example not an exhaustive list. ISO 8601 is a global standard.
It’s also recommended for use on the web by W3C.

Emile,
Je te conseille de consulter Emile !

Ci joint une classe qui peut te rendre service.
Ne cherche pas comment elle fonctionne, utilise la simplement

I advise you to consult Emile !

Attached is a class that can do you a favor. Don’t look for how it works, just use it

dateTime.xojo_binary_project.zip (12.6 KB)

The is no time component in “2024-11-28”

Dim thedate as date
Dim Now as new date
If not Parsedate(“28/11/2024”, thedate) then
msgbox “Incorrect date format”
else
Msgbox thedate.SQLdate + " " + now.Longtime
end if