Home All Groups Group Topic Archive Search About

convert adDBtimeStamp to datetime

Author
29 Sep 2005 1:59 PM
Lucian Baltes
Hello,

I use a SQL Server with ODBC driver and >NET C#.

I want to convert a date field with adDBtimeStamp format to a DATETIME
format, but no solution could be found till now.

My query is as follows:

SELECT     received_at as EXPR1
FROM       TTable
WHERE      datepart(week(datetime(received_at)))>10

Has anybody any solution for conversion?




*** Sent via Developersdex http://www.developersdex.com ***

Author
29 Sep 2005 2:15 PM
David Portas
What is the SQL datatype of "received_at" and what are you attepting to
do with it? adDBtimeStamp maps to a DATETIME type in SQL Server so no
conversion should be necessary. However your example code isn't valid
in SQL Server - there is no WEEK or DATETIME function and your syntax
for DATEPART is wrong.

Maybe the following was what you intended, assuming you are in fact
dealing with a DATETIME column:

SELECT received_at AS expr1
FROM TTable
WHERE DATEPART(WEEK,received_at)>10 ;

--
David Portas
SQL Server MVP
--
Author
29 Sep 2005 3:30 PM
Lucian Baltes
It seems that no conversion is made and no explicit conversion could be
applied.

for the sequence:

SELECT received_at AS expr1
FROM TTable
WHERE DATEPART(WEEK,received_at)>10

the outcome is:
Driver]Expected lexical element not found: )

*** Sent via Developersdex http://www.developersdex.com ***
Author
14 Oct 2005 1:49 PM
Steve Kass
Lucian,

If the adDBtimeStamp values are seen as strings of the
form 'yyyymmddhhmmss', try this:

declare @t table (
  adDBtimeStamp char(14)
)

insert into @t values ('20051012171534')

select
  convert(datetime,
    substring(adDBtimeStamp,1,8) + space(1) +
    substring(adDBtimeStamp,9,2) + ':' +
    substring(adDBtimeStamp,11,2) + ':' +
    substring(adDBtimeStamp,12,2),
  112) as SQLdt
from @t


Steve Kass
Drew University

Lucian Baltes wrote:

Show quote
>Hello,
>
>I use a SQL Server with ODBC driver and >NET C#.
>
>I want to convert a date field with adDBtimeStamp format to a DATETIME
>format, but no solution could be found till now.
>
>My query is as follows:
>
>SELECT     received_at as EXPR1
>FROM       TTable
>WHERE      datepart(week(datetime(received_at)))>10
>
>Has anybody any solution for conversion?
>
>
>
>
>*** Sent via Developersdex http://www.developersdex.com ***

>

AddThis Social Bookmark Button