Converting sql data from datetime to string

Converting sql data from datetime to string

Postby Marco Turco » Sun Nov 12, 2017 1: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Converting sql data from datetime to string

Postby Rick Lipkin » Sun Nov 12, 2017 2:49 pm

Marco

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

Rick Lipkin

Code: Select all  Expand view  RUN

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 ) ))
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Converting sql data from datetime to string

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Converting sql data from datetime to string

Postby Marco Turco » Tue Nov 14, 2017 1: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
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Re: Converting sql data from datetime to string

Postby nageswaragunupudi » Tue Nov 14, 2017 6:06 pm

Date as Character:

DTOC( tDateTimeValue )

Time as character:

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 36 guests