Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

get Time from Full Date

by the3factory 3/13/2008 6:15:00 AM

Sql Server does not provide any function to get Time in hh:mm tt format from DateTime field. So you can get time using this function.

Using the code

First of all you have to create this function in your databse. and then you can get the time from the full datetime value.use the following sql script to create this function.

CREATE FUNCTION dbo.getTime
(
@dt DateTime
)
RETURNS varchar(8) AS
BEGIN
Declare @retTime as varchar(8)
Select @retTime= Right('0' + Cast(((DatePart(HH,@dt)+11) % 12+1) as varchar(2)),2) + ':' + Right('0' + Cast(DatePart(mi,@dt)as varchar(2)),2)+' ' + case when DatePart(HH,@dt) > 11 then 'PM' else 'AM' end
return @retTime
END     

Tags:

DataBase | SQL

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0