February 14, 2006 at 9:17 pm
Hi guys,
A small query...I am trying to get the Time part only from a DateTime column, I am using it in my S.P
I have right(Login,7) but the problem i face is i cant display it in my datagrid in ASP.net since the column I am referencing is Login is not found?
how do i resolve this issue?
February 14, 2006 at 9:35 pm
Who did tell you datetime is the same as varchar?
Why are you trying to use varchar functions for datetime values?
There is a UDF to solve the problem:
IF EXISTS (SELECT * FROM sysobjects WHERE name = N'TimeOnly')
DROP FUNCTION TimeOnly
GO
CREATE FUNCTION dbo.TimeOnly
(@DT datetime)
RETURNS datetime
AS
BEGIN
RETURN convert(datetime, @dt - convert(int, @dt - 0.5))
END
GO
SELECT dbo.TimeOnly (getdate())
GO
_____________
Code for TallyGenerator
February 14, 2006 at 10:48 pm
select CONVERT(VARCHAR(10), getdate(),8) ;
Try this
February 14, 2006 at 10:51 pm
If you want to get the only time part, then
use the following Query :-
select convert(varchar,getdate(),108)
February 14, 2006 at 11:21 pm
and this one is much better
SELECT RIGHT(CONVERT(VARCHAR,GETDATE()),7) AS TIME
February 15, 2006 at 1:42 am
Yes, I think the main problem is naming the time column. Use "as xxx", like Veeresh above. Also explicit conversion from datetime to varchar is preferable...
February 4, 2009 at 6:58 am
very useful post
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply