One way to cope with the format problems of dates and other types is to delegate that task to ODBC.
For example a query like
Code:
Select * From remotetable WHERE datetimefield = ?ltDateTime
Works not only with MS SQL Server, but also with MySQL for sure and with many other databases, too. This mechanism of parameterisation is also the best against sql injection. Besides you can use the native foxpro datettime type.
So the initial question really is, what type do you get from the remote backend? If it is a string (likely it is, because I can't remember a date setting making Foxpro report months as three letter acronyms). What is the query you do, do you use conversion function for querying or is the data really stored as string? Because if so, you're just making life harder to yourself.
The rule of thumb is: Keep data in their native types as long as you can and only change to the human readability for the reason of human readability.
The type of string you want to send is rather in that direction, but you may also be able to again use ?ltDatetime to send a native format data and let the ODBC driver do the conversion as the remote backend understands it via:
Code:
Insert Into remotetable (datetimefield) Values (?ltDateTime)
In both cases you just need to set a ltDateTime Variable in Foxrpo to the desired datetime.
For example, with SET SYSFORMATS ON and with changing extended system settings for time and date formatting you can make Foxpro display DATETIME() as 25-May-2012 19.16.00, even with the unusual seperator characters.
Rule of thumb is, to stay in native date types as long and as best as you can.
If you nevertheless need that output format, let me correct Mikes little mistake in the last line:
Code:
tDateTime = DateTime()
SET DATE AMERICAN
lcOutput = TRANSFORM(tDateTime )
* Get rid of the dashes
lcOutput = STRTRAN(lcOutput, "-", "")
* Change the colons (in the time element) to dots
lcOutput = STRTRAN(lcOutput, ":", ".")
? lcOutput
And code to get the dateparts from the input you get (with the three letter month short name) could be:
Code:
lcDateTime = "24-May-12 08:42:33"
* decompose into string parts
lcDay = LEFT(lcDateTime,2)
lnMonth = (AT(SUBSTR(lcDateTime,4,3),"JanFebMarAprMayJunJulAugSepOctNovDec")+2)/3
lcMonth = TRANSFORM(lnMonth,"@RL 99")
lcYear = SUBSTR(lcDateTime,8,2)
lcYear = IIF(VAL(lcYear)<50,"20"+lcYear,"19"+lcYear)
lcTime = SUBSTR(lcDateTime,11)
* finally convert these string parts to a native foxpro datetime via Evaluate() of a datetime literal:
ltDateTime = EVALUATE(TEXTMERGE("{^<<lcYear>>-<<lcMonth>>-<<lcDay>> <<lcTime>>}"))
? ltDateTime
Maybe you could shorten the code using more elegant expressions, but sometimes straight forward is the best to do to get more or less undertandable code.
Bye, Olaf.