frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

SQLite Date and Time Functions (2007)

https://www2.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions
46•1vuio0pswjnm7•1d ago

Comments

needusername•7h ago
Ignoring time zones, the Boris Johnson approach to time zones.
biofuel5•6h ago
I just store millis or nanos as INTEGER. Never found the correct use for string datetimes, also they're slower and take much more space
simonw•6h ago
The main advantage of string datetimes is that you can decipher what they mean just by looking at them in a table.
o11c•6h ago
Just CREATE VIEW something (ahead of time, so it's ready) for the rare time you need to visually inspect it.
bob1029•5h ago
This is the best path in my experience. I typically store timestamps as 64-bit unix seconds in the same way.

On the application side, I use Dapper and DateTimeOffset to map these to a domain type with proper DateTime/UTC fields.

I've found that storing time as integers in the database has some interesting upsides. For example, range queries over the field tend to be faster.

crazygringo•5h ago
For storing actual moments in physical time (especially past events), and where the time zone is irrelevant, for sure.

But for storing future events that are tied to a time zone, you need the string with time zone. Otherwise when time zone definitions change, your time will become wrong.

hudsonja•4h ago
Timezones just give you a set of rules to determine a cultural description of a given point in time. How is timezone any more or less relevant to a future vs. past event?
jbverschoor•4h ago
Timezones can change.
pgwhalen•3h ago
The cultural rules tend to be more important when describing future events, where the “human friendly” description is what really defines it.

When describing past events, it’s often most precise to describe the literal universe time that it happened.

Obviously these are just generalities, whether you choose one strategy or another depends on the specific use case.

crazygringo•43s ago
As I said, because time zone definitions change.

If daylight saving time gets cancelled by legislation, then the event happening at noon two summers from now, you will still probably want to happen at noon -- the new noon.

But changes to timezones don't apply retroactively.

jiggunjer•1h ago
UTC is pretty stable though. I recall they will obsolete leap seconds somewhere in the next 10 years
stillpointlab•6h ago
The fact that they do not include the trailing 'Z' for UTC timestamps is a frustration for me. It caused a few hours of debugging since JavaScript date parsing assumes that dates that lack the trailing Z are in the client time zone. I had to add a hack to check if a UTC date did or did not have the trailing Z and append the Z if it was missing.

This is made worse when you have a lot of `createdAt` columns that get set to NOW. You have to deal with the missing Z in all places where it matters. And in general, it is pointless to use the `localtime` parameter since that is the server time, and for UI I want to display the time local for the user. So I want to deal exclusively in UTC on the server and do any time zone conversions on the client.

Worth noting that when I changed to PostgreSQL, its date function does add the Z which makes life easier in general. But it is an inconsistency to be aware of if you use both DBs.

noitpmeder•6h ago
Seems it should be trivial to extend/change the data type to add a Z. It's not like it's storing the ISO8601 string in the db itself, so it's just a presentation later that is giving you the string.
em500•5h ago
You don't actually know how they're stored. SQLite has a rather idiosyncratic approach to datetimes: it does not provide any datetime data types (the only SQLite data types are NULL, INTEGER, REAL, TEXT and BLOB). It's left entirely to the user how to store datetimes using these types. What SQLite does provide are functions (documented on the submitted page) that translate some datetime representations (stored using the one of the mentioned basic datatypes) to other formats. So you can choose to store your datetimes in unix-epoch INTEGER and use the translation functions to output ISO8601 TEXT when needed, or the other way around: there is no correct or even preferred way in SQLite.
ncruces•5h ago
Try one of these:

  strftime('%Y-%m-%dT%H:%M:%SZ')
  strftime('%Y-%m-%dT%H:%M:%fZ')
You can use this to convert whatever internal format you're using for presentation, in a SELECT statement. Like so (be sure to read up on 'auto', to see if it fits):

  strftime('%Y-%m-%dT%H:%M:%fZ', column, 'auto')
nikeee•5h ago
`current_timestamp` also returns something like `2025-06-15 19:50:50` while the docs state that it is ISO 8601. Except that this is not ISO 8601 due to the T missing in the middle. This has caused some headaches due to different formats of JS's `.toISOString()` and SQLite's `current_timestamp`. The datetime column is basically only for documentation. I wish they had some timestamptz type which rejects insertions containing invalid datetime formats.
chuckadams•2h ago
ISO8601 is a collection of different formats, and using a space instead of a ‘T’ is one of the allowed variations. I’m not sure anything implements the full spec perfectly.
ncruces•6h ago
Why not link to the most recent version?

https://sqlite.org/lang_datefunc.html

SJC_Hacker•2h ago
They probably should have just omitted date/time functionality completely, keeping in spirit the "Lite" in SQLite. Their implementation is so bare bones as to be nearly useless compared to say PostgreSQL.

Users could then just use either client or user created functions to do the conversion, in whatever makes sense for the app. If all you need is GMT, just store seconds/milliseconds etc. from epoch. If you want to store older dates like in a historical database, strings or day/month/year split or even just single integer. Name columns appropriately to avoid ambiguity, like "gmt_ms" and it shouldn't cause too many problems.

dardeaup•2h ago
I disagree. I think that date/time data is pervasive enough to even warrant having built-in column data types for them. It's helpful when you care about data integrity.
DecoPerson•44m ago
One huge benefit of using SQLite over a traditional server/client DBMS is the ability to easily add SQL functions that call into your host language and memory-space.

For example, we’re using better-sqlite3 which has a convenient API for adding SQL functions [1], and we have dozens of helper methods for dealing with time using the temporal-polyfill module.

We have custom JSON-based serialisation formats for PlainDate, PlainTime, PlainDateTime, ZonedDateTome, etc. Then in SQL we can call ‘isDate_Between__(a, b, c)`.

a, b, and c are deserialised by the JS (TS) function, the logic is run, and the result is returned to SQLite. We’ve had no performance issues with this approach, though we’re only dealing with simple CRUD stuff. No big data.

You can even use these functions with generated columns and indexes, but I haven’t found a proper use for this yet in my work.

[1] https://github.com/WiseLibs/better-sqlite3/blob/HEAD/docs/ap...

somat•15m ago
sqlite is pretty great, but I have to admit the main reason I keep using postgres, even in situations where sqlite would probably be a better fit, is that I like the postgres standard function library better.

But I also use postgres as a sort of better excel, so what do I know. My desktop instance has a million silly small tables, you know back of envelope ideas, exploratory data, to do lists, etc

Telephone Exchanges in the UK

https://telephone-exchanges.org.uk/
89•petecooper•5h ago•29 comments

Modifying an HDMI dummy plug's EDID using a Raspberry Pi

https://www.downtowndougbrown.com/2025/06/modifying-an-hdmi-dummy-plugs-edid-using-a-raspberry-pi/
177•zdw•9h ago•47 comments

First-Ever Supercritical CO2 Circuit Breaker Debuts

https://spectrum.ieee.org/sf6-gas-replacement
22•rbanffy•2h ago•4 comments

Twin – A Textmode WINdow Environment

https://github.com/cosmos72/twin
38•kim_rutherford•5h ago•7 comments

Canyon.mid

https://canyonmid.com/
228•LorenDB•12h ago•137 comments

Childhood leukemia: how a deadly cancer became treatable

https://ourworldindata.org/childhood-leukemia-treatment-history
154•surprisetalk•12h ago•36 comments

First 2D, non-silicon computer developed

https://www.psu.edu/news/research/story/worlds-first-2d-non-silicon-computer-developed
65•giuliomagnifico•3d ago•12 comments

How to modify Starlink Mini to run without the built-in WiFi router

https://olegkutkov.me/2025/06/15/how-to-modify-starlink-mini-to-run-without-the-built-in-wifi-router/
252•LorenDB•12h ago•70 comments

Why SSL was renamed to TLS in late 90s (2014)

https://tim.dierks.org/2014/05/security-standards-and-name-changes-in.html
152•Bogdanp•11h ago•67 comments

Datalog in miniKanren

https://deosjr.github.io/dynamicland/datalog.html
79•deosjr•9h ago•7 comments

Simplest C++ Callback, from SumatraPDF

https://blog.kowalczyk.info/a-stsj/simplest-c-callback-from-sumatrapdf.html
72•jandeboevrie•7h ago•59 comments

Datalog in Rust

https://github.com/frankmcsherry/blog/blob/master/posts/2025-06-03.md
233•brson•14h ago•24 comments

Chemical knowledge and reasoning of large language models vs. chemist expertise

https://www.nature.com/articles/s41557-025-01815-x
9•bookofjoe•1d ago•2 comments

David Attenborough at 99: 'I will not see how the story ends'

https://www.thetimes.com/life-style/celebrity/article/david-attenborough-book-extract-age-99-lj3rd2fg7
94•herbertl•4h ago•44 comments

Show HN: Seastar – Build and dependency manager for C/C++ with Cargo's features

https://github.com/AI314159/Seastar
37•AI314159•5h ago•30 comments

It’s nearly impossible to buy an original Bob Ross painting (2021)

https://thehustle.co/why-its-nearly-impossible-to-buy-an-original-bob-ross-painting
107•rmason•5h ago•100 comments

Cyborg Embryos Offer New Insights into Brain Growth

https://spectrum.ieee.org/embryo-electrode-array
10•rbanffy•3d ago•0 comments

How fast can the RPython GC allocate?

https://pypy.org/posts/2025/06/rpython-gc-allocation-speed.html
28•todsacerdoti•5h ago•5 comments

Fields where Native Americans farmed 1000 years ago discovered in Michigan

https://www.smithsonianmag.com/smart-news/massive-field-where-native-american-farmers-grew-corn-beans-and-squash-1000-years-ago-discovered-in-michigan-180986758/
151•CoopaTroopa•3d ago•62 comments

DARPA program sets distance record for power beaming

https://www.darpa.mil/news/2025/darpa-program-distance-record-power-beaming
4•gnabgib•2h ago•0 comments

Cure Dolly's Japanese Grammar Lessons

https://kellenok.github.io/cure-script/
45•agnishom•1d ago•9 comments

An Introduction to the Hieroglyphic Language of Early 1900s Train-Hoppers

https://www.openculture.com/2018/08/hobo-code-introduction-hieroglyphic-language-early-1900s-train-hoppers.html
25•squircle•5h ago•3 comments

Show HN: StellarSnap – Explore NASA APODs, simulate orbits, learn astronomy

https://stellarsnap.space
14•stellarsnap•2d ago•0 comments

Foundations of Computer Vision

https://visionbook.mit.edu
134•tzury•15h ago•6 comments

SQLite Date and Time Functions (2007)

https://www2.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions
46•1vuio0pswjnm7•1d ago•22 comments

The experience continues until you stop experiencing it

https://strangemachine.tv/safespace/popov/
64•durakot•8h ago•19 comments

A skyscraper that could have toppled over in the wind (1995)

https://www.newyorker.com/magazine/1995/05/29/the-fifty-nine-story-crisis-citicorp-center
41•georgecmu•9h ago•30 comments

The Art of Lisp and Writing (2003)

https://www.dreamsongs.com/ArtOfLisp.html
162•Bogdanp•18h ago•62 comments

Ruby on Rails Audit Complete

https://ostif.org/ruby-on-rails-audit-complete/
168•todsacerdoti•3d ago•134 comments

Text-to-LoRA: Hypernetwork that generates task-specific LLM adapters (LoRAs)

https://github.com/SakanaAI/text-to-lora
102•dvrp•3d ago•10 comments