Multiple Choice Question (MCQ)

Question: What will be the output of the following VBA code?
Debug.printformat(#1/1/2017#,'yyyy/mm/dd')
A. 01-01-2017
B. Sun, Jan01, 2017
C. 01-01-2017
D. Sunday, January 01, 2017
Correct Answer: 01-01-2017
Explanation

The output of the following VBA code will be "2017/01/01". The "Debug.print" statement is used to print the result of the format function to the Immediate Window. The format function takes two arguments: the first one is a date expression, in this case it is the date "#1/1/2017#" which represent January 1, 2017. The second argument is the "format string" which is "yyyy/mm/dd", that means year/month/day in 4 digits, 2 digits and 2 digits respectively.

This code will format the date in the format of year/month/day and return it as a string. The year is represented by 4 digits, month by 2 digits and day by 2 digits, as mentioned in the format string. The date 1/1/2017 becomes 2017/01/01 using the format specified.