Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql server convert date to 10 digit integer for comparison

I'm working with a database where dates are stored as 10 digit integers and where the user can query information within certain calendar date ranges. I was wondering what are the steps for converting a calendar date to a 10 digit integer for comparison with dates stored in a database.

I'm working with sql server 2000.

like image 251
jsmith Avatar asked Jan 29 '26 14:01

jsmith


1 Answers

You need SELECT DATEADD(second, 1240494225, '19700101') to convert the number to a date and SELECT DATEDIFF(second, '19700101', @some_date) to go the other way.

like image 131
Martin Smith Avatar answered Feb 03 '26 09:02

Martin Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!