Part of my job is to answer questions that the executives have which are difficult to determine, so I set up a little website which has a dashboard of various different queries and graphs I created. Of course, this leads to more requests and sometimes this falls outside the bounds of what I can easily do. For example, I couldn’t determine how many people were using a particular tool on our website because I didn’t have access to the the logs.
After pestering our IT department for several months, I finally got them to create a new database account for me so I could parse the statistics from our websites for reporting purposes. It’s a proprietary windows app which uses a MS-SQL database for storage, so I hooked it all up and started looking around at the tables.
It all looked pretty straightforward… for each website there was a set of tables named logical things like sumVisits and sumPaths, etc. And I could even find the results from custom reports I had already designed, making it very easy for me to gather the data I required. The table looks like this:
----------------------------
| DateVal | Visits | Views |
----------------------------
| 2454020 | 1304 | 1632 |
| 2454021 | 1124 | 2553 |
| 2454022 | 502 | 964 |
| 2454023 | 707 | 1388 |
| 2454024 | 1164 | 1332 |
----------------------------
Pretty simple, right? Now all I have left is to figure out what the hell this DateVal references. Normally these things reference another table so I check to see what it is a foreign key of. If you don’t speak database, that’s jargon for “lookup value referenced in another table”. Except in this case, it didn’t exist. And after poking around in every single table I determined that no, it simply wasn’t referencing anything else.
So what the hell is this DateVal anyhow? Just scanning the table visually shows that they are incrementing by one per day, so it’s a date counter of some sort. So what was 2454020 days ago, and why do I care about it? I read the documentation but it was not helpful in the slightest.
Since I work in MySQL quite a bit, I check there first to figure out what the original reference date is: “SELECT date_sub(current_date, interval 2454020 day)”. Except MySQL refuses to return a result for that, its date_sub routine isn’t built to handle such large numbers. Fine, I’ll try it in python. “print datetime.datetime.now() - datetime.timedelta(2454020)” Damnit, that overflows too.
This is getting ridiculous… this stupid application is issuing dates which I can’t seem to process, and can’t even figure out what the hell it’s doing. As a last ditch effort to try to figure out what the hell is going on, I consult the oracle of our times, google. Searching for one of the DateVal values with the word “date” finally told me what I was looking at: a Julian Date Count.
“The Julian Day Count is a uniform count of days from a remote epoch in the past (-4712 January 1, 12 hours Greenwich Mean Time (Julian proleptic Calendar) = 4713 BCE January 1, 12 hours GMT (Julian proleptic Calendar) = 4714 BCE November 24, 12 hours GMT (Gregorian proleptic Calendar)). ” — ref
That just happens to be about 2.5 million days ago, which this stupid application helpfully uses to tell you what day the results happened on. It’s extremely useful for a website analytics program, in case an archaeologist happens to find a 6000 year old webserver which uses Apache Common Log Format logs, they won’t have a problem at all.
As a footnote, I should also point out that when I finally implemented that feature it was in the language PHP. PHP is well known for having way too many function names, and it just so happens that they have a built in feature to serve the extremely common purpose of converting Julian Date Counts into standard timestamps.
print jdtounix(2454020);
?>
You’ve got to be kidding me.