A Batch File to Produce the Billboard Music Chart for 40 Years Ago Today

I used batch files to open certain webpages automatically, on certain days of the week or month.  In my WEEKLY.BAT file, I wanted to add a line that would open the Billboard Hot 100 list of songs as of 40 years ago today.  So then, every Saturday, that Billboard webpage would open automatically in Firefox (or whatever browser I designated), updated to the day that was 40 years ago on that date.

Note:  to open a command window, I could use Start > Run > CMD.  Better, I could use the Open Command Window Here option.

I already knew that I could enter a command like this in a command window, or run it in something like that WEEKLY.BAT file:

start Firefox “http://www.billboard.com/charts/hot-100?chartDate=1972-12-08″

This would run without requiring a more formal reference to “firefox.exe” because I had saved a shortcut to Firefox, called simply “Firefox,” in C:\Windows.  (Or at least I think that’s what I did; it seemed to work with some other programs, like Excel.  I think the executable had to be found in the PATH for this to work.)  I kept a folder with copies of a half-dozen regularly used shortcuts like this (e.g., Firefox, Excel), so whenever I reinstalled Windows it was easy to just copy them all into C:\Windows.  But just using “start firefox.exe” would have been OK too.

The question was, how could I get today’s date into that command, so that the computer would automatically tell Firefox to open the Billboard Hot 100 chart page for January 3, 1973, or April 14, 1974, or whatever was 40 years ago from the date when the batch file was running?

The DOS-like batch language built into Windows 7 (which I was using) included a DATE command.  DATE would produce something like “The current date is:  Sat 12/01/2012.”  (I think the arrangement would vary according to the Date settings specified in Control Panel > Region and Language.)  In the format just shown, “The current date is:” was apparently supplied by the system and did not count.  So if I wanted to display the digits pertaining to the month, I would type this on the command line:  echo %date:~4,2%.  That is, give me the two characters beginning at the fourth character of the date output.  (Apparently the space after “Sat” didn’t count either.)  So “echo %date:~4,2%” would produce 12, if the current month was December.

Therefore, I could get the appropriate Firefox command (above) by typing this on the command line:

echo start Firefox “http://www.billboard.com/charts/hot-100?chartDate=%date:~10,4%-%date:~4,2%-%date:~7,2%”

That would produce this output:

start Firefox “http://www.billboard.com/charts/hot-100?chartDate=2012-12-01″

Instead of using the ECHO command, I could assign all that text to a variable, which I might call BBURL.  That command would look almost exactly like the ECHO command:

set BBURL=start Firefox “http://www.billboard.com/charts/hot-100?chartDate=%date:~10,4%-%date:~4,2%-%date:~7,2%”

And then I could get the same output as above by typing ECHO %BBURL%.  So in my batch file, I would just need those two lines:  first, the one defining BBURL (i.e., the one starting with “set BBURL,” as just shown), and then the one echoing BBURL as a variable (i.e., ECHO %BBURL%).

But I wasn’t done.  Yes, I was getting an echoed display of the command:  start Firefox http://www.billboard.com/charts/hot-100?chartDate=2012-12-01.  But that command was not actually running.  It was just displaying on the screen.  As far as the computer was concerned, it was not an actual command to open Firefox to that Billboard webpage; it was just a set of letters and numbers, functionally the same as “My mama loves me.”  I needed to tell the command window to go ahead and execute that command.  I thought this was going to require some additional command; but when I posted a question to ask about it, the answer came back that I was already overkilling it.  Instead of using ECHO %BBURL%, I should have just used %BBURL%.

Now I needed the other part:  to subtract 40 from the year, so as to get the proper URL for the date that was 40 years ago today.  The solution seemed to be to add a year calculation.  Altogether, the batch file to automatically open the Billboard Hot 100 list for 40 years ago today contained these three commands:

set year1=%date:~10,4% & set /a year2=year1-40
s
et BBURL=start Firefox “http://www.billboard.com/charts/hot-100?chartDate=%year2%-%date:~4,2%-%date:~7,2%”
%BBURL%

About these ads
This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s