sql server - Converting from R POSIXlt to T-Sql datetime -


i need restructure r posixlt object appropriate t-sql query going return sql datetime. imagine there should way conver posixlt double , use double make sql datetime, not able figure out how that. here have tried:

date = as.posixlt(sys.time()) date_num = as.double(date) 

after copied contents of date_num (1469491570) , attempted paste following sql query see happens:

select convert(datetime, convert(varchar(10), 1469491570)); 

however, errors out, guess expected, since expects string representation of date not random number...

edit: looking find can convert posixlt number of tics or milliseconds from, say, 1900 , uses number create t-sql datetime.

the function:

julian(x, origin = as.date("1970-01-01"), ...) 

can convert posix object number of days specified origin should able convert number of seconds or milliseconds.

for example:

as.numeric(julian(as.date("2016-07-25")))  

is 17007 days jan 1, 1970 (beginning of time unix) or

as.numeric(julian(as.date("2016-07-25"), origin = as.date("1900-01-01")))  

or 42574 days close beginning of time windows.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -