Function to convert sql datetime to zulu time format

  • I need a function to  convert SQL server date/time format to zulu time format that would include leading and trailing zeros. For example, 6/8/2004 9:34:20 AM converted to 093420. Any help would be greatly appreciated.

    I had been using the following function which does not include leading and/or trailing zeros:

    CREATE  function [dbo].[fn_DateTime2ZuluTime] (@date datetime)

    returns int

    as

    begin

        declare @timeint int

        select @timeint = (datepart(hour, @date) * 010000) +

                          (datepart(minute, @date) * 100) +

                          (datepart(second, @date))

        return @timeint

    end

  • I have no clue of what are the rules for zulu time but:

    select  replace(convert (varchar(8), @date, 14),':','')

     

    You are aware that you are changing datetime to time only, right?

     


    * Noel

  • Actually the term zulu refers to greenwich (mean time) and not the format

  • Yes, I only concerned with the time portion of date/time.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply