Formatted Dates
February 21, 2020
Regular readers of this blog know that I work with a team of programmers, sysadmins and database administrators to maintain a large legacy database application, running on Oracle and HP-UX, and Scheme is nowhere in sight. Lately I have been “stealth programming” by writing awk programs in shell wrappers, because shell programming is a normal part of our environment. One thing I have been doing is formatting reports with awk. That frequently requires a formatted date string, either for today or some other day; gawk provides the strftime
function to format dates, but Posix awk, which is what HP-UX provides, doesn’t. So I wrote my own.
Your task is to write a function that formats dates; use any convention you like to determine how the date is formatted. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
Let’s display the Modified Julian Date. Some C:
@Pascal: nice stuff. Common Lisp formatting is amazing.
Here’s an improved version of my minimal approach that using the Posix clock_gettime function for a more accurate result. Also, I made the format precision a parameter – default is to show microdays, which are slightly less that a tenth of a second: