CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    Norway
    Posts
    32

    get database datetime with ADO

    I'm trying to get the (mssql 7.0)database date, and has a ADO connection to the database.
    How can I use ADO to receive the date.
    (In sql I can write 'select CURRENT_TIMESTAMP' but how can i receive the raw sql output from ADO)


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: get database datetime with ADO

    dim rs as adodb.recordset
    rs.open "select getdate()"
    msgbox rs.fields(0) ' contains current date
    rs.close


  3. #3
    Join Date
    Jul 1999
    Location
    Norway
    Posts
    32

    Re: get database datetime with ADO

    Thanks!
    The result is very good, but the returning date is formatted, and it is not Y2K safe (not good to show customers). Do You have any solution on this problem (without lots of string handlings...)
    - I wold prefer the result from the query analyzer (1999-07-29 08:45:21.623) in stead of the result from ADO (7/29/99 08:49:54)
    Suggestions? (thanks!)


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: get database datetime with ADO

    this works, but is not optimized.

    select convert(varchar(4), datepart(year, getdate())) + "-"
    + convert(varchar(2),datepart(month, getdate())) + "-"
    + convert(varchar(2),datepart(day, getdate())) + " "
    + convert(varchar(2),datepart(hour, getdate())) + ":"
    + convert(varchar(2),datepart(minute, getdate())) + ":"
    + convert(varchar(2),datepart(second, getdate()))

    improve it by calling getdate() only once and also include padding with leading zeros if you want.


  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: get database datetime with ADO

    Ok, I haven't seen your request for "without lots of string handling".
    Here is a solution - I do it on the client in VB


    de.Command1
    MsgBox Format(de.rsCommand1.Fields(0), "YYYY-MM-DD HH:MM")
    de.rsCommand1.Close



    I used the DataEnvironment this time. Command1 is still only a "select getdate()"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured