Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date type
Message
 
 
To
09/12/2016 03:32:13
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01644735
Message ID:
01644767
Views:
47
>>I am just about completing a fairly extensive import utility of CSV files, and have a potential concern about this type of date found as a character (I was thinking there was a built in VFP way to make this conversion, but can't remember what it was) :
>>
>>December 12, 2016 or Dec. 12, 2016
>>
>>If I allow a user to select the above as a Date field, I need to convert it to a normal 12/12/2016 which is stored as a date field in the table. Anyone know the best way to do this? I will not know ahead how the date is stored and will be testing it before appending it to the actual date field in the table.
>
>Here's what I use for such purposes. Note that it covers only the "10-dec-2016" case (i.e. text month in the middle) and only english months. For months in front it would have to be adjusted. Also, set("date") is decided before the call, as generally all the dates in one sheet are of the same type (i.e. american, british, german etc), although I've seen exceptions to this :facepalm:.
>
>
*---------------------------------------------------
>PROCEDURE makedate(tuD, tlFuture)
>*[2016/06/28 14:54:15] ndragan - added future for expiry dates.
>	LOCAL ldD, lny
>
>	DO CASE
>		CASE EMPTY(tuD)
>			ldD={}
>		CASE 	VARTYPE(tuD)$"T"
>			ldD=TTOD(tuD)
>		CASE 	VARTYPE(tuD)$"D"
>			ldD=tuD
>		CASE VARTYPE(tuD)="C"
>			DO CASE
>				CASE LEN(tuD)<6 OR NOT ISDIGIT(tuD)
>					ldD={}
>					oLog.LOG(tuD+" in a date field")
>					oCnt.ADD("Date field contains "+tuD)
>				CASE NOT ISDIGIT(GETWORDNUM(tuD,2," -./"))
>					lcMo=GETWORDNUM(tuD,2," -./")
>					lnMo=ROUND(ATC(lcMo, "dum jan feb mar apr may jun jul aug sep oct nov dec ")/4,0)
>					lnDay=VAL(GETWORDNUM(tuD,1," -./"))
>					lnYear=VAL(GETWORDNUM(tuD,3," -./"))
>					IF lnYear<100
>						lnYear = lnYear + IIF(BETWEEN(lnYear, 1, 25), 2000, 1900)
>					ENDIF
>					ldD=DATE(lnYear, lnMo, lnDay)
>				CASE 	LEN(tuD)>10
>					ldD=TTOD(CTOT(tuD))
>				OTHERWISE
>					ldD=CTOD(tuD)
>			ENDCASE
>		OTHERWISE
>			ldD={}
>	ENDCASE
>	lny=YEAR(ldD)
>*[2014/03/03 10:03:26] nDragan - there are about fifty cases where dates of birth are in wrong century
>	DO CASE
>		CASE NOT tlFuture AND BETWEEN(lny, 2030, 2090)
>			ldD=DATE(1900+lny%100, MONTH(ldD), DAY(ldD))
>			oCnt.ADD("Fixed date in century "+TRANSFORM(lny-lny%100))
>		CASE BETWEEN(lny, 130, 199)
>			ldD=DATE(1900+lny%100, MONTH(ldD), DAY(ldD))
>			oCnt.ADD("Fixed date in century "+TRANSFORM(lny-lny%100))
>		CASE BETWEEN(lny, 200,219)
>			ldD=DATE(2000+lny%100, MONTH(ldD), DAY(ldD))
>			oCnt.ADD("Fixed date in century "+TRANSFORM(lny-lny%100))
>		CASE BETWEEN(lny, 1, 1790)
>			ldD=DATE(1900+lny%100, MONTH(ldD), DAY(ldD))
>			oCnt.ADD("Fixed date in century "+TRANSFORM(lny-lny%100))
>*		CASE lny>2100
>	ENDCASE
>	RETURN ldD
>
>The oCnt is a collection, and the .add() method maintains a counter for each string passed, so the items are string+number (of occurrences) pairs. In the end it logs each of them. You can remove the oCnt lines and oLog lines as well - I keep them just to check the number of irregular cases in the sheets. If more than a hundred, then I adjust the code; below hundred, I recommend that they fix it manually afterwards.

Ok, I didn't see this post till today, and this might work for me with a little tweaking. The app is only used in English. Thanks for this.
Previous
Reply
Map
View

Click here to load this message in the networking platform