Get Date and Time from SQL-Server

DirkSimonDirkSimon Member Posts: 9

i want to get data from SQL-Server per ADO. The problem is the field date from the type datetime.

With the following code i get only then date-part of the field:

rs.Open('SELECT TrendNdx, Date, Value FROM ASample WHERE ...

Does anybody know, how i can get the time-part?



  • ArhontisArhontis Member Posts: 667
    Maybe you could use the DATEPART routine of the sql (place your data/time filed) on the second parameter. Like:
    SELECT DATEPART(hh,myField) as Hours FROM ....
    and use the Hours field on C/Al to get the value...

    Returns an integer representing the specified datepart of the specified date.

    DATEPART ( datepart , date )


    Is the parameter that specifies the part of the date to return. The table lists dateparts and abbreviations recognized by Microsoft® SQL Server™.

    Datepart Abbreviations
    year yy, yyyy
    quarter qq, q
    month mm, m
    dayofyear dy, y
    day dd, d
    week wk, ww
    weekday dw
    hour hh
    minute mi, n
    second ss, s
    millisecond ms
Sign In or Register to comment.