OK, so I got tired of hack and slashing some scripts that I’ve been working on lately and decided to bring out The Big Guns.
One specific script needed to know the amount of time that has lapsed since a certain date. Because my trusty copy of Perl did not have any good date libraries installed, I got to reexperience the wonder and glory that is epoch time.
Perl’s standard libraries allow you to get epoch time, which is the number of seconds that have elapsed since January 1, 1970 (the beginning of Nerd Standard Time). By using a few built-in Perl functions, I was able to get the epoch time for a date constructed of specific values, such as month (0-11), day (0-30), year (offset + 1900), etc.
By subtracting two such values, I get an integer that is a number of seconds between these two epoch times. From there, a series of simple divides yeilded me an array that expressed the difference between two dates, with the value a 1 representing minutes (the granularity I was after), 2 was hours, and so on.
I’m so excited about my accomplishment that now I am not tired. Any questions why I scored a 93 on my Nerd Score?
Related Articles
1 user responded in this post