Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format month\day to include 0 if less than 10

Status
Not open for further replies.

mdav2

Programmer
Aug 22, 2000
363
GB
I am trying to format the day\month of the date to include the "0" if it is less than 10. I thought that I might be able to use a simple function to do this in VFP, like FORMAT in VBA. It needs to be returned as a string.

I couldn't find a similar so I've had to use the PADL command to achieve this (see below). Just out of interest is there an equivalent of the VBA FORMAT command in VFP?

Code:
x = PADL(ALLTRIM(STR(MONTH(DATETIME()))),2,'0')

Mark Davies
Warwickshire County Council
 
I've created a little function that works quite well.
Code:
**********************
FUNCTION func_nicedate
**********************
** Author:  Steve Long
** Purpose: Takes a date value, converts it to a text string using MDY and removes any leading zero for the day, returning the new string 
**				(i.e. {06/09/2004} = 'June 9, 2004')
**			Including the second optional parameter as a .T. will prefix the return value with the day of the week
**				(i.e. {06/09/2004} = 'Wednesday, June 9, 2004')
** Note:  The return value is a String, not a Date
LPARAMETERS tdDateIn, tlIncludeDOW
IF tlincludeDOW
	RETURN CDOW(tdDateIn) + ", " + STRTRAN(MDY(tdDateIn)," 0"," ")
ELSE
	RETURN STRTRAN(MDY(tdDateIn)," 0"," ")
ENDIF


Steve

 
Thanks for the replys as always. I was surprised that you wouldn't have to alltrim and str the month value because it's numeric. Will make the SQL easier to ready.

Mark Davies
Warwickshire County Council
 
If you need the whole date with leading zeroes:

Code:
cDate = DTOS(DATE(2006,2,4))
* For U.S. format:
? SUBSTR(cDate,5,2)+'/'+RIGHT(cDate,2)+'/'+LEFT(cDate,4)
* For European format:
? RIGHT(cDate,2)+'/'+SUBSTR(cDate,5,2)+'/'+LEFT(cDate,4)

Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top