May 31, 2005 at 1:06 pm
hi guys
when I run this query below, I also want the seconds to be displayed in the time column! How can I do that?
SELECT DATENAME(weekday, LEFT (getdate(), 12)) AS Day, LEFT (getdate(), 12) AS
Date, RIGHT (getdate(), 7) AS [time]
May 31, 2005 at 1:33 pm
This will get you the hh:mm:ss but not am/pm:
SELECT DATENAME(weekday, LEFT (getdate(), 12)) AS Day, LEFT (getdate(), 12) AS
Date, convert(varchar, getdate(),8) AS [time]
May 31, 2005 at 1:33 pm
Sorry for the late reply... forgot the hit send :
Select convert(varchar(8), GetDate(), 108) as 24H_Time
May 31, 2005 at 1:34 pm
Is synchronised replying a new olympic event now?
May 31, 2005 at 1:40 pm
Add this last part to get am/pm:
SELECT DATENAME(weekday, LEFT (getdate(), 12)) AS Day, LEFT (getdate(), 12) AS
Date, convert(varchar, getdate(),8) + Right(convert(varchar, getdate(),9),2) as [time]
Edit: But I guess that doesn't make much sense with a 24 hour format
May 31, 2005 at 1:44 pm
Wouldn't it be better to extract the hour part and do a % 12 on it so that you don't get 23H15:13 PM?? >> we know it's pm by that time.
May 31, 2005 at 1:49 pm
thats great remi, thanks a lot
May 31, 2005 at 1:54 pm
This seems to work:
SELECT DATENAME(weekday, LEFT (getdate(), 12)) as DAY,
convert(char(20), getdate(),9)+ ' ' + Right(convert(varchar, getdate(),9),2) as [Date/Time]
DAY Date/Time
------------------------------ -----------------------
Tuesday May 31 2005 3:40:03 PM
May 31, 2005 at 1:57 pm
Yup that does it.
May 31, 2005 at 2:12 pm
Don't need the "Left" in the DATENAME part.
SELECT DATENAME(weekday, getdate()) as DAY,
convert(char(20), getdate(),9)+ ' ' +
Right(convert(varchar, getdate(),9),2) as [Date/Time]
DAY Date/Time
------------------------------ -----------------------
Tuesday May 31 2005 3:56:23 PM
June 1, 2005 at 1:22 am
Just out of curiosity, don't you think this is nothing but a presentational issue and an easy task for any client app?
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
June 1, 2005 at 7:12 am
Hey Frank, do you have a link where I can learn to show more smiley faces than the one I already way too overused ().
BTW I also agree on the presentation stuff argument.
June 1, 2005 at 7:27 am
Sure, use IE and activate somewhere in your profile the use of the HTML Editor.
...or have a website you can link to.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
June 1, 2005 at 7:54 am
actually Iam working on the timeclock. I gave the getdate() to just get the answer. I have 2 time columns in my reports view and I need the clockin, clockout difference with seconds
June 1, 2005 at 8:02 am
Something along these lines?
declare @dt1 datetime, @dt2 datetime
select @dt1 = getdate(), @dt2 = getdate()-0.0833333333333333333 -- 2 hours earlier
select
@dt1, @dt2,
convert(varchar,dateadd(second,datediff(second,@dt2,@dt1),0),108)
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply