How to Modify the Results of the MDY() Function

Last reviewed: March 20, 1998
Article ID: Q145605
3.00 3.00b | 2.60a
WINDOWS    | MACINTOSH
kbprg kbhowto kbcode

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b
  • Microsoft FoxPro for Macintosh, version 2.6a

SUMMARY

When the day of a month is between the first and the ninth, the MDY function returns the date with a zero (0) in front of the day. This article gives you a program that removes the zero (0) from the results of the MDY format.

MORE INFORMATION

Normally, a date in the form of month/day/year does not have a zero in front of a day. The MDY() function always places a zero in front of single-digit days. The program listed in this article uses the functions MDY() and STRTRAN() to remove the blank space and zero and replace it with only a blank space.

The program searches the value returned from the MDY() function for a blank space followed by a zero. If it finds this combination, the STRTRAN() function replaces it with a blank space.

WARNING: The MDY() function changes the data type of the variable from a date type to a character type so that the unwanted zero can be removed. If the variable must remain as a date type, no setting or function exists to remove it. Furthermore, after modifying the format of the variable, you can't use the CTOD() functions to convert it back to its original date format.

Create a program file named Test that contains the following code. Then run the program.

   SET CENTURY ON
   x={01/01/1996}
   y={01/01/2000}
   ? MDY(x)
   ? MDY(y)
   ? STRTRAN(MDY(x)," 0"," ")
   ? STRTRAN(MDY(y)," 0"," ")
   SET CENTURY OFF


Additional reference words: 3.00 3.00b VFoxWin 2.60a FoxMac
KBCategory: kbprg kbhowto kbcode
KBSubcategory: FxprgGeneral
Keywords : FxprgGeneral kbcode kbhowto kbprg
Version : 3.00 3.00b | 2.60a
Platform : MACINTOSH WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.