Important: The deadline for this event has passed. Solutions are available in VBScript, Windows PowerShell, and Perl. |
In What’s the Difference, competitors will be asked to read a parameter from a command line and perform date calculations based on that parameter.
Not a native speaker of English? These event instructions are also available in the following languages: Chinese (Simplified); Chinese (Traditional); French; German; Japanese; Portuguese Brazilian; Russian; and Spanish. For more information, and to access these localized instructions, see the Scripting Games International page.
| About This Event | |
| Event Scenario |
Division | Beginner |
Deadline | Tuesday, February 26, 2008 (8:00 AM PST) |
Points Awarded | 10 |
It’s pretty common in the world of system administration scripting to have to work with dates. One task that’s frequently required is to compare dates in order to determine how old a file is, how long ago an event was created, and so on.
In this event, the user will be required to enter a date as a command-line parameter when the script is run. Your task is to read in that date and compare it to the current system date. Your output will consist of three parts:
| • | Days. The number of days between the system date and the input date. |
| • | Months. The number of months between the system date and the input date. |
| • | Months/Days. The number of months plus the number of days between the system date and the input date. |
Here’s an example. Suppose the system date is February 15, 2008, and the user enters a date of March 3, 2008. This would be the output:
Days: 17 Months: 1 Months/Days: 0 / 17
As you can see, there are 17 days between February 15 and March 3. Because February is in February and March is, well, in March, the difference from February to March is one month. But notice that when we display the months and days there really isn’t an entire month between these two dates. Therefore, the total time between these dates is 0 months and 17 days.
If instead of March 3, 2008, the user had entered March 3, 2009, this would be the output:
Days: 382 Months: 13 Months/Days: 12 / 16
The total number of days between February 15, 2008 and March 3, 2009 is 382. The number of months between the two is 13. The number of months plus days to get from February 15, 2008 to March 3, 2009 is 12 months and 16 days.
A few things to note on this event. The first is that when we test the entries for this event, we’ll always enter a date as the first parameter following the script command, and that date will always be a valid date. Second, you only need to check for dates after the current date – no need to count backwards. Finally, we will use the English (United States) regional and language option settings, and we will always enter dates using a string value similar to this: March 3, 2008