FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Converting sql data from datetime to string
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Converting sql data from datetime to string
Posted: Sun Nov 12, 2017 01:59 PM

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.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Converting sql data from datetime to string
Posted: Sun Nov 12, 2017 02:49 PM
Marco

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

Rick Lipkin

Code (fw): Select all Collapse
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 ) ))
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Converting sql data from datetime to string
Posted: Mon Nov 13, 2017 10:35 AM
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 858
Joined: Fri Oct 07, 2005 12:00 PM
Re: Converting sql data from datetime to string
Posted: Tue Nov 14, 2017 01:39 PM

Hi, thank you for your reply.
I only need to extract the data and time components and put them in two char variables.

Best Regards,



Marco Turco

SOFTWARE XP LLP
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Converting sql data from datetime to string
Posted: Tue Nov 14, 2017 06:06 PM

Date as Character:

DTOC( tDateTimeValue )

Time as character:

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

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion