CREATE FUNCTION dbo.ToTicks ( @DateTime datetime2 ) RETURNS bigint AS BEGIN DECLARE @Days bigint = DATEDIFF( DAY, '00010101', cast( @DateTime as date ) ); DECLARE @Seconds bigint = DATEDIFF( SECOND, '00:00', cast( @DateTime as time( 7 ) ) ); DECLARE @Nanoseconds bigint = DATEPART( NANOSECOND, @DateTime ); RETURN @Days * 864000000000 + @Seconds * 10000000 + @Nanoseconds / 100; END
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter