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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character date to date fields

Status
Not open for further replies.
Jul 7, 2003
95
0
0
US
I have a field that is character containing dates...

Ex: 19991102

I want to convert this to a date field...

whats the proper syntak to convert this field to another fields of proper date?
 
Try this:

lcDate = "1991102"

ldDate = func_str2date(lcDate)
? ldDate


FUNCTION func_str2date
LPARAMETERS tStr
RETURN CTOD(SUBSTR(tStr,5,2)+"/"+SUBSTR(tStr,7,2)+"/"+LEFT(tStr,4))

Steve
 
What SGLong gave you was the longhand reverse version of DTOS(). Strange that there is no simple reversed function. Just keep in mind:

(1) your current VFP date type (SET DATE TO AMERICAN, MDY, YMD, DMY, etc.) may require a different ordering of the substrings.

(2) this works fine if the century is included. If the century is not included, then the code would have to be adjusted so the century is calculated.

dbMark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top