Discussing data time-formats, someone mentioned to me how he stores datetime (in a human-readable format) using floats as yyyymmdd.hhmmss
, so 2019-09-18, 11:29:30am
would become 20190918.112930
I'm trying to find out if this guy has invented his own format or if it is used (and described) elsewhere too - and if so, how is it even called...?
It’s homespun
I have seen a lot of date and time formats, and I have not seen this one before. My go is that his guy or his organization invented it themselves.
Edit: Thank you for confirming in the comment. Since comments are not always permanent on Stack Overflow, I quote here, you said:
Finally got confirmation from the source: it's homespun indeed.
As an aside I don’t like it. A float
is stored in a binary format internally, and only after formatting it into decimal does it become human readable. In addition you need to format it with exactly 6 decimals of fraction, or any number of digits of the time of day may be missing if they happen to be 0. Using a float
for a “human readable” date and time was not what formatting of floating-point numbers was meant for, it’s a hack.
Use ISO 8601
For a human-readable format I recommend ISO 8601. Here 2019-09-18, 11:29:30am
becomes 2019-09-18T11:29:30
. Or even better and still within ISO 8601, convert to UTC and append a Z
to denote UTC. So if your original time was in Europe/Berlin time zone, it would become 2019-09-18T09:29:30Z
. As you can see, ISO 8601 is even more human readable than you friend’s format, and it is sortable as strings (as long as the years don’t go beyond 9999).