Microsoft KB Archive/110667

From BetaArchive Wiki

Article ID: 110667

Article Last Modified on 2/24/2005



APPLIES TO

  • Microsoft Visual Basic 3.0 Professional Edition
  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q110667

SYMPTOMS

For the date of Sunday January 2, 1994, the Format("01/02/94","ww") function returns week number 2 instead of week number 1.

NOTE: Visual Basic handles dates according to the Country settings in the International option of the Windows Control Panel. When the Country is set to United States, dates such as "01/05/94" are by default interpreted with the month followed by the day, as in mm/dd/yy. For most other Country settings, the day precedes the month, and "05/01/94" is interpreted as dd/mm/yy.

CAUSE

In the Format function, weeks start on a Sunday and go through the following Saturday. In 1994, January 1 is a Saturday, which is the only day in week 1. Week 2 of 1994 starts on Sunday January 2.

Therefore, the Format("01/01/94","ww") function returns 1, and Format("01/02/94","ww") returns 2.

STATUS

This behavior is by design.

MORE INFORMATION

Below are some of the format expressions for the day, week, month, and quarter, as supported by the Format function:

dd - Displays the day as a number with a leading zero (01-31).

ddd - Displays the day as an abbreviation (Sun-Sat).

dddd - Displays the day as a full name (Sunday-Saturday).

w - Displays the day of the week as a number (1 for Sunday through 7 for Saturday.)

ww - Displays the week of the year as a number (1-53).

m - Displays the month as a number without a leading zero (1-12). If m immediately follows h or hh, the minute rather than the month is displayed.

mm - Displays the month as a number with a leading zero (01-12). If m immediately follows h or hh, the minute rather than the month is displayed.

mmm - Displays the month as an abbreviation (Jan-Dec).

mmmm - Displays the month as a full month name (January-December).

q - Displays the quarter of the year as a number (1-4).


For more information, see the Format and Format$ function topics in the Visual Basic Help menu.

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Double-click the form. Add the following to the Form Load event code:

          Sub Form_Load ()
             form1.Show
             Print Format("01/01/94", "ww dddd")
             Print Format("01/05/94", "ww dddd")
          End Sub
                            
  3. Start the program, or press the F5 key to see the following print:

    1 Saturday

    2 Wednesday

    The Format function correctly shows Wednesday January 5 as being in week 2 of 1994. Close the form to end the program.


Keywords: kbprb KB110667