locked
How to get current Time in HHmmssSSS format RRS feed

  • Question

  • User-1061665085 posted

    Hi,

    I tried using

    SELECT replace(Convert (varchar(8),GetDate(), 108),':','') + SELECT DATEPART(ms,SYSDATETIME());

    but it gives only HHmmss part not milli second.

    Please help!

    Thanks

    Aiden

    Thursday, November 19, 2015 8:32 AM

Answers

  • User2103319870 posted

    mr.ab18

    but it gives only HHmmss part not milli second.

    You just need to use DateFormat 114 instead of 108

    SELECT replace(Convert (varchar(15),GetDate(), 114),':','')

    Note that I have increased the size of Varchar to 15 so that it will include the microseconds also

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 8:54 AM
  • User354416029 posted

    you can do it using following query

     SELECT CAST(GetDate() AS time(7)) AS 'time'

    for more reference refer msdn link .

    hope this will be useful.

    Thanks,

    Chintan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 8:57 AM
  • User77042963 posted
    select format(getdate(),'HHmmssfff')

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 9:24 AM

All replies

  • User2103319870 posted

    mr.ab18

    but it gives only HHmmss part not milli second.

    You just need to use DateFormat 114 instead of 108

    SELECT replace(Convert (varchar(15),GetDate(), 114),':','')

    Note that I have increased the size of Varchar to 15 so that it will include the microseconds also

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 8:54 AM
  • User-1061665085 posted

    mr.ab18

    but it gives only HHmmss part not milli second.

    You just need to use DateFormat 114 instead of 108

    SELECT replace(Convert (varchar(15),GetDate(), 114),':','')

    Thanks mate! 

    Also this working after lot of try

    SELECT convert(varchar,replace(Convert (varchar(8),GetDate(), 108),':','')) +  convert(varchar,DATEPART(ms,SYSDATETIME())) 

    :)

    Thursday, November 19, 2015 8:56 AM
  • User354416029 posted

    you can do it using following query

     SELECT CAST(GetDate() AS time(7)) AS 'time'

    for more reference refer msdn link .

    hope this will be useful.

    Thanks,

    Chintan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 8:57 AM
  • User77042963 posted
    select format(getdate(),'HHmmssfff')

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2015 9:24 AM
  • User-1061665085 posted

    select format(getdate(),'HHmmssfff')

     Stroke of a genius :) and thanks all other people who helped!

    Friday, November 20, 2015 2:51 AM