You must Sign In to post a response.

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?


Comments

#84857    Author: Rajaraman    09 Oct 2006 Member Level: Gold   Points : 2

select convert(varchar,getdate(),108)

#84858    Author: Rajaraman    09 Oct 2006 Member Level: Gold   Points : 2

select convert(varchar,getdate(),108)

#84859    Author: Rajaraman    09 Oct 2006 Member Level: Gold   Points : 2

select convert(varchar,getdate(),108)

#84862    Author: Vadivel Mohanakrishnan    09 Oct 2006 Member Level: Gold   Points : 2

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    Author: madhavi reddy  09 Oct 2006 Member Level: Silver   Points : 2

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

#84899    Author: S.V.Sirish    10 Oct 2006 Member Level: Silver   Points : 2

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    Author: Mohit Chawla  10 Oct 2006 Member Level: Silver   Points : 2

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    Author: Ravindra R    10 Oct 2006 Member Level: Gold   Points : 2

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.