SQL Server Float Dates in Ruby

Yesterday, I ran into a situation doing integration with a security app of having to calculate a date to float for SQL Server. Dates as float in SQL Server are calculated from 01/01/1900 00:00:00 so here is the code I used:


  @date = (Time.now.to_f.ceil/86400) + 24105

Time.now.to_f.ceil will return the number of seconds at the end of the day since Epoch Time 01/01/1970. Diving by 8400 will convert that to days and adding 24105 will add the number of days since 01/01/1900.

So to get the time for SQL Server as a float for 30 days from now this is the exact code I used:


  @end_date = ((Time.now + 30.days).to_f.ceil / 86400) + 24105


There are 11 Comments for SQL Server Float Dates in Ruby

I just ran into this today, nearly the exact same situation: SQL Server for a security app from a Rails application. Thanks for putting this together! It helped a lot. The only difference is, the script that I am dealing with is using (Time.now.to_f.floor / 86400) + 25569 Sort of interesting. Still trying to figure out why it want that route instead of the way you mentioned.
By the way, I'm assuming that the "8400" is a typo, meant to read 86400? That confused me thoroughly until I realized that.
货架 上海网站优化
nice post..
thanks for sharing
This is great. I would LOVE to see more useful topics on this site!
Beautiful! and amazing before and after. The articles are different & nice!
You have composed an extremely good article.
Lovely work!
PAPER CUP MACHINE is an automatic machine with multi-working station. Paper cup making machine produces one-side film-coated paper cup through the procedure of automatic paper feeding, sealing, oil silicon lubrication, bottom punching, heating, knurling, curling and cup discharge. This kind of cup can be for tea, coffee, milk, ice-cream etc.
Thanks for sharing this nice post. I will keep your article in my idea.

Add A Comment

Name:
Email:
URL:
Message:


Artist Websites