Microsoft Knowledge Base
XL: Visual Basic Interprets mm:ss as Month Not Minutes
Last reviewed: June 11, 1997
Article ID: Q105954
The information in this article applies to:
- Microsoft Excel for Windows, version 5.0
- Microsoft Excel for the Macintosh, version 5.0
- Microsoft Excel for Windows 95, version 7.0
SUMMARY
When a date format is evaluated in a Visual Basic module, it may be changed from months to minutes.
The following macro command will return months followed by seconds:
MsgBox Format(Now, "mm:ss")
While Microsoft Excel uses the format mm:ss for minutes and seconds, Visual Basic uses the format "nn:ss" for minutes and seconds.
This issue will not be seen by using the format "h:mm:ss". Visual Basic will interpret this correctly as hours:minutes:seconds, as this is a less ambiguous format.
MORE INFORMATION
Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.
Example
The following Visual Basic macro creates a message box with three numbers that display the system date and time. The first number is formatted as month and seconds, while the second two numbers display minutes and seconds.
Sub My_string() Dim Msg, NL NL = Chr(10) Msg = Format(Now, "mm:ss") & NL 'Returns "Month & Seconds" Msg = Msg & Format(Now, "nn:ss") & NL 'Returns "Minutes & Seconds" Msg = Msg & Application.Text(Now, "mm:ss") 'Returns "Minutes & Seconds" MsgBox Msg End Sub
REFERENCES
"Visual Basic User's Guide," version 5.0, pages 111-113
For more information about User Defined Date/Time Formats, choose the Search button in Visual Basic Reference Help and type:
Formatting Times
Additional reference words: 5.00 7.00 Last reviewed: June 11, 1997 |