Home Reversing an integer-converted datetime
Reply: 2

Reversing an integer-converted datetime

B3S
1#
B3S Published in 2018-01-11 14:18:12Z

In T-SQL the function

CONVERT(INT, GETDATE())

returns an integer like 43110.

Is there any way to reverse this function and roll back the 43110 value to the original datetime format?

OlafW
2#
OlafW Reply to 2018-01-11 14:24:29Z

You can use

CONVERT(DATETIME, 43110)

to get the datetime back - but your former

CONVERT(INT, GETDATE())

has been rounded - it should have been something about 43109.625

SELECT CONVERT(DATETIME, 43109.625)

Best way would be to use

SELECT (CONVERT(FLOAT, GETDATE()))

for retrieving the decimal representation.

MatSnow
3#
MatSnow Reply to 2018-01-11 14:26:42Z

This will return the date portion only:

CONVERT(DATETIME, 43110)

If you need the time portion too, then use FLOAT instead of INTEGER:

CONVERT(FLOAT, GETDATE()) -- results in a number like 43109.6431769676

and back:

CONVERT(DATETIME, 43109.6431769676)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330654 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO