datetime with seconds

  • 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]

  • 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]

  • Sorry for the late reply... forgot the hit send :

    Select convert(varchar(8), GetDate(), 108) as 24H_Time

  • Is synchronised replying a new olympic event now?

  • 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

  • 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.

  • thats great remi, thanks a lot

  • 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

  • Yup that does it.

  • 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

  • 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]

  • 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.

  • 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]

  • 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

  • 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