STOD()

The String To Date function converts just about ANY date format to the MM/DD/YY or MM/DD/YYYY format!

It can be used

In FoxPro Reports

FoxPro Entry Screens

FoxPro Programs

FoxPro is a registered trademark of Microsoft Corporation

It is sometimes a bit frustrating to enter a date FoxPro, with leading zeros required on dates such as 01/01/95.

 

FoxPro provides various date conversion functions, DTOC(), CTOD(), DTOS(), CDOW(), etc. But none of these provide the flexibility of Microsoft Access and Symantec's Q&A for entering dates. So, I decided to write the ultimate date function, called STOD() for String to Date.

 

Enclosed is the STOD() program, and a file to test it with STODTEST.DBF with the command:

 

BROWSE FIELDS Text, Date=STOD(Text)

If I missed any, let me know. You can change the program yourself to put in additional "holidays" like "Ground Hog's Day" etc.

 

* STOD() - converts any date string (almost) to a valid date expression

* An improvement on the CTOD() date function - much more user friendly.

* DBF date fields require you to put in tedious leading zeros and the year.

* Xbase has a DTOS() return YYYYMMDD, but no function for converting YYYYMMDD

* Created on a Saturday night after having enough of difficult date entry.

* 1994 C I Corporation 703-486-2222 Rick Shaddock

 

* Syntax: STOD(<expC>) Returns: MM/DD/YYYY format

 

* Supported formats for <expC> for 03/05/1994

* Mar 15, 94 15 Mar 94

* Mar 15, 1994 15 Mar 1994 3/15/1994 15/3/1994 1994/3/15

* March 15, 94 15 March 94 03/15/94 15/03/94 94/03/15

* March 15, 1994 15 March 1994 03/15/1994 15/03/1994 1994/03/15

* March 15th 94 15th of March 94 3-15-94 15-3-94 1994-3-15

* March 15th 1994 15th of March 1994 3-15-1994 15-3-1994 1994-3-15

* March Fifteenth 94 Fifteenth March 94 03-15-94 15-03-94 94-03-15

* March Fifteenth 1994 Fifteenth of March 03-15-1994 15-03-1994 1994-03-15

* Mid March 94 940315 3.15.94 15.3.94 94.3.15

* Middle March 1994 19940315 3.15.1994 15.3.1994 1994.3.15

* March the 15th, 94 Ides of March 94 03.15.94 15.03.94 94.03.15

* March the 15th, 1994 Ides of March 1994 03.15.1994 15.03.1994 1994.03.15

* 315 0315 1503 31594 031594

 

* Inconsistent separators are allowed or no separator at all

* 3.15/94 3 15-94 3/15-94 3/15.94 31594 150394

 

* Assumes current month and year if only day is given (ex. March 1994)

* Mar 15 March 15 15 Mar 15th of March 3/15 15/3 03-15 3.15

* 15 15th Fifteenth Mid

 

* Removes extra words and spaces

* ? stod('March the 15th of 1994')

 

* If the first number is greater than 12, it is assumed to be a day

* ? stod('15-3-94') returns 03/15/94 (D-M-Y format)

* ? stod('3-15-94') returns 03/15/94 (M-D-Y format)

 

* Holidays

* ? stod('Independence Day 1776') returns 07/04/1776

* ? stod('Labor Day 92') returns 09/07/92 (first Monday)

* ? stod('Labor Day') returns 09/05/94 (first Monday)

* ? stod('Christmas') returns 12/25/94 (current year)

 

* Days of the week (this coming week assumed)

* Mon Tuesday Last Wed Last Thursday Next Fri Next Saturday

 

* Works for special key words and period endings

* ? stod('Year End 94') returns 12/31/94

* ? stod('Today') returns today's date

* ? stod('Last Week') returns 7 days before today's date

* ? stod('Feb End') returns 02/28/94 (not leap year)

* ? stod('Feb End 92') returns 02/29/92 (leap year)

 

* Example of use of STOD() in a Valid procedure:

* m.cDate =space(20) && Initialize character varible

* @ 10,5 say 'Date:' get m.cDate && Get character var for date

* read && read into memory

* dDate =stod(m.cDate) && dDate is a true date variable

* m.cDate =dtoc(dDate) && Convert back to MM/DD/YY form

* show gets && Display standard form date

 

Computer Instruction Corporation
Crystal Plaza One
3300 Fairfax Drive, Suite C
P.O. Box 100411
Arlington, VA 22202
703-486-2222
877-727-9070 Fax
800-319-3190

CIC@CICorp.com

Return to C I Corporation Software

Return to C I Corporation Home page

 

.