You must Sign In to post a response.
  • Category: SQL Server

    how will i get time using SQL query?

    i hav a datetime field in a table. if i select the field, it shows both date with time. but i want to show only the time?

    how will i get time using SQL query?
  • #84857
    select convert(varchar,getdate(),108)

  • #84858
    select convert(varchar,getdate(),108)

  • #84859
    select convert(varchar,getdate(),108)

  • #84862
    Yes ppl have already answered. Just go through the Convert function and choose appropriate number as per ur desired format. GetDate() is the function to print the current datetime.


    Best Regards
    Vadivel
    MVP SQL Server

  • #84895
    hi,
    yes.GetDate() is the function to display datetime

  • #84899
    Hello,

    I think the below query should work

    Select Convert(varchar,DatePart(HH,WH)) + ':' + Convert(varchar,DatePart(MI,WH)) + ':' + Convert(varchar,DatePArt(SS,WH)) from WorkingHours

    Replace WH and WorkingHours with your fieldname and Tablename

    - Sirish

  • #84909
    use getdate() which will fetch you the date and time and then convert it into the time format i.e. 108 format.

    Convert(varchar, getdate(),108)

  • #85046
    Convert(varchar, getdate(),108)


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.