Page 1 of 1

Converting sql data from datetime to string

Posted: Sun Nov 12, 2017 1:59 pm
by Marco Turco
Hi all,
I'm reading an sql db with a datetime field using fwh+xharbour ADO.
The variable I got for this field is a "T" type format, how can I convert it to a string for further manipulations ?

Thank you in advance.

Re: Converting sql data from datetime to string

Posted: Sun Nov 12, 2017 2:49 pm
by Rick Lipkin
Marco

Here is a function that was given to me and takes Date\Time ValType "T" to ValType "D"

Rick Lipkin

Code: Select all

Function TtoDate( tDate )

If empty( tDate)
   Return( ctod("00/00/00"))
Endif

If ValType( tDate ) = "D"
   Return(tDate )
Endif

Return( stod( substr( ttos( tDate ), 1, 8 ) ))
 

Re: Converting sql data from datetime to string

Posted: Mon Nov 13, 2017 10:35 am
by nageswaragunupudi
The variable I got for this field is a "T" type format, how can I convert it to a string for further manipulations ?
You can do all kinds of manipulations by retaining the value as type "T" ( DateTime type). There is more flexibility with "T" type data than broken down parts of Date and Time separately.
If you explain what kind of manipulations you want to do, I shall provide my suggestions.

Re: Converting sql data from datetime to string

Posted: Tue Nov 14, 2017 1:39 pm
by Marco Turco
Hi, thank you for your reply.
I only need to extract the data and time components and put them in two char variables.

Re: Converting sql data from datetime to string

Posted: Tue Nov 14, 2017 6:06 pm
by nageswaragunupudi
Date as Character:

DTOC( tDateTimeValue )

Time as character:

LEFT( AFTERATNUM( " ", TTOC( tDateTimeVal ) ), 5 )