Ramblings of a DBA

Tara Kizer
posts - 166, comments - 837, trackbacks - 75

My Links



Search this Blog


Post Categories


November 2003 Blog Posts

Convert from/to Java time

I recently had to create a UDF that would convert a Java time value to a datetime value.  We have an application that stores dates and times as the number of milliseconds since Jan. 1, 1970.  Well that isn't very pleasant to the human eye when trying to debug things.  So, here is a function to convert it to datetime: CREATE FUNCTION udf_ConvertJavaTimeToDateTime(@milliseconds BIGINT)RETURNS DATETIMEAS BEGIN DECLARE @DateTime DATETIME SELECT @DateTime = DATEADD(s, @milliseconds/1000, '1970-01-01 00:00:00.000' ) RETURN @DateTime END   And here is a function to convert a datetime value to Java time: CREATE  FUNCTION udf_ConvertDateTimeToMSSince1970(@DateTime DATETIME)RETURNS BIGINTAS BEGIN DECLARE @seconds BIGINT SELECT @seconds = DATEDIFF(s, '1970-01-01 00:00:00.000', @DateTime) RETURN...

posted @ Monday, November 10, 2003 4:16 PM | Feedback (1) | Filed Under [ SQL Server - General ]

Powered by:
Powered By Subtext Powered By ASP.NET