How To Modify the Results of the MDY() Function (145605)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0
  • Microsoft Visual FoxPro for Windows 3.0b
  • Microsoft FoxPro for Macintosh 2.6a

This article was previously published under Q145605

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
				

Modification Type:MinorLast Reviewed:7/1/2004
Keywords:kbcode kbhowto KB145605