Click here to Skip to main content
15,891,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

My table has one field name "Docdate". This field is stored like this "2006-01-05 00:00:00.000". Is it possible to get Time?
Ex: 09:35 or 10:24 minute.

If it is possible,How can i do?

Thanks

TONY
Posted

If the date stored does not have the time value then you are out of luck, if not then read this :
http://stackoverflow.com/questions/3201432/how-to-get-time-part-from-sql-server-2005-datetime-in-hhmm-tt-format[^]
 
Share this answer
 
Comments
Abhinav S 28-May-12 1:06am    
5 Of course.
Mehdi Gholam 28-May-12 1:18am    
Thanks Abhinav!
Prasad_Kulkarni 28-May-12 1:20am    
Good one 5+
Mehdi Gholam 28-May-12 1:29am    
Thanks Prasad!
If you have stored the time as 00:00:00 then you won't be able to get the time.

Change the frontend code to pass in an appropriate time value.
Once that is done, you can pick up the time as described here[^].
 
Share this answer
 
Comments
Mehdi Gholam 28-May-12 1:19am    
5'ed
Abhinav S 28-May-12 1:19am    
Thank you.
Prasad_Kulkarni 28-May-12 1:20am    
+5!
Abhinav S 28-May-12 1:37am    
Thank you.
Yes you can, please refer Date time formats[^]

Or else

Try this:

SQL
SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7))
 
Share this answer
 
v2
Comments
Abhinav S 28-May-12 1:06am    
5!
Prasad_Kulkarni 28-May-12 1:19am    
Thanks Abhinav!
Mehdi Gholam 28-May-12 1:19am    
5'ed
Prasad_Kulkarni 28-May-12 2:43am    
Thanks Mehdi!
Try with this :

SQL
select ISNULL(REPLACE(REPLACE(RIGHT('0'+LTRIM(RIGHT(CONVERT(Nvarchar,GETDATE(),100),7)),7),'AM',''),'PM',''),'')
 
Share this answer
 
v2
Yes u can use the Format method to show the date in perticular format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900