Reputation: 7530
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...?
Upvotes: 1
Views: 2783
Reputation: 86369
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 your friend’s format, and it is sortable as strings (as long as the years don’t go beyond 9999).
Upvotes: 2
Reputation: 26916
According to Wikipedia, this would be similar to the ISO 8601, which permits, all of the following for date and time combined:
except that the T
to separate the time from the date is replaced by .
and the time-zone information is dropped.
That specific format has limited popularity either in the yyyymmdd.HHMMSS
or the C's strftime()
-compatible %Y%m%d.%H%M%S
form.
As far as using float
for date and time the way you suggests, it depends on the precision and machine representation.
If the system is following IEEE 754 basic standard (which is what most modern C compiler stick to), you would need at least float64
.
However, it is not common to do so.
This might be in part because it may be difficult to correctly predict the accuracy of the time information, and it is not as bit-efficient as the Unix time.
Given that the only positive feature it has is that it can rely on standard %f
from sprintf()
, I would only see it advantageous when strftime()
is not available or a performance bottleneck.
Upvotes: 1
Reputation: 37
Not sure if we are talking about SQL date format. If so, this date format is present in SQL Statements. Not sure about the name, it's called in different ways: non-standard, ISO, Other format and so on. Is present also in PHP.
Upvotes: 1