Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change date from British to American?
Message
From
09/07/2021 03:27:06
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01681748
Message ID:
01681758
Views:
72
>Hi,
>
>Can you change the date from British to American using SET DATE command?
>
>For example, say you have a char column in a DBF like this:
>14/10/2020
>08/03/2012
>16/2/2020
>3/3/2010
>all the above characters show the date in a British format. Note the above are not dates but char representation of a date.
>Now I want to change them to American format (mm/dd/yyyy)
>Can it be done without many SUBSTR()?
>
>TIA

Dmitry, most probably you've already done this by now, but since you asked "without many SUBSTR()", two possible solutions
CLEAR

LOCAL ARRAY Source[1]
LOCAL DateStr AS String

ALINES(m.Source, "14/10/2020,08/03/2012,16/2/2020,3/3/2010", 0, ",")

* using VFP functions

FOR EACH m.DateStr IN m.Source

	? m.DateStr, STREXTRACT(m.DateStr, "/", "/") + "/" + STREXTRACT(m.DateStr, "", "/") + STREXTRACT(m.DateStr, "/", "", 2, 4)
	? m.DateStr, STUFF(m.DateStr, 1, AT("/", m.DateStr, 2) - 1, STREXTRACT(m.DateStr, "/", "/") + "/" + STREXTRACT(m.DateStr, "", "/"))
	?

ENDFOR

* using Regular Expressions

LOCAL Regx AS VBScript.RegExp

m.Regx = CREATEOBJECT("VBScript.RegExp")

m.Regx.Pattern = "([0-9]+)/([0-9]+)/([0-9]+)"

FOR EACH m.DateStr IN m.Source

	? m.DateStr, m.Regx.Replace(m.DateStr, "$2/$1/$3")

ENDFOR
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform