Forums » .NET » SQL Server »

how will i get time using SQL query?


Posted Date: 09 Oct 2006      Posted By:: asath     Member Level: Silver    Member Rank: 0     Points: 2   Responses: 8



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?






Responses

#84857    Author: Rajaraman      Member Level: Gold      Member Rank: 79     Date: 09/Oct/2006   Rating: 2 out of 52 out of 5     Points: 2

select convert(varchar,getdate(),108)

 
#84858    Author: Rajaraman      Member Level: Gold      Member Rank: 79     Date: 09/Oct/2006   Rating: 2 out of 52 out of 5     Points: 2

select convert(varchar,getdate(),108)

 
#84859    Author: Rajaraman      Member Level: Gold      Member Rank: 79     Date: 09/Oct/2006   Rating: 2 out of 52 out of 5     Points: 2

select convert(varchar,getdate(),108)




 
#84862    Author: Vadivel Mohanakrishnan      Member Level: Gold      Member Rank: 26     Date: 09/Oct/2006   Rating: 2 out of 52 out of 5     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      Member Level: Silver      Member Rank: 0     Date: 09/Oct/2006   Rating: 2 out of 52 out of 5     Points: 2

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


 
#84899    Author: S.V.Sirish      Member Level: Silver      Member Rank: 0     Date: 10/Oct/2006   Rating: 2 out of 52 out of 5     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      Member Level: Silver      Member Rank: 0     Date: 10/Oct/2006   Rating: 2 out of 52 out of 5     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      Member Level: Gold      Member Rank: 0     Date: 10/Oct/2006   Rating: 2 out of 52 out of 5     Points: 2

Convert(varchar, getdate(),108)

 
Post Reply

 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.



Return to Discussion Forum
Start new thread

Subscribe to Subscribers
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John

Online Members

vivek
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India