如何获取mysql以将DateTime输出为儒略日数? [英] How can I get mysql to output a DateTime to Julian day number?

查看:89
本文介绍了如何获取mysql以将DateTime输出为儒略日数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在使用用于Ruby的MySQL gem ,但我没有为日期比较提供合理的支持. Mysql::Time类仅给我提供访问器方法,例如年,月,秒等.如果可以将其转换为Ruby DateTime对象,则可以做更好的日期比较.如何将MySQL的DateTime字段转换为儒略日编号,该日期可以传递给 ?

Basically I am using the MySQL gem for Ruby, and I have no reasonable support for date comparison. The Mysql::Time class only gives me only accessor methods like year, month, second, etc. I could do much better date comparison, if I could turn this into a Ruby DateTime object. How can convert MySQL's DateTime field to a Julian day number which can be passed to DateTime.jd?

推荐答案

考虑使用 Ruby/DBI 而不是直接使用MySQL gem. Ruby/DBI应该自动为您处理到标准Ruby类的转换,并且作为一项额外的奖励功能,如果您更改了正在运行的DBMS,则对DBI的使用不会更改.

Consider using Ruby/DBI instead of using the MySQL gem directly. Ruby/DBI should take care of the conversion into standard Ruby classes for you automatically, and as an added bonus feature if you ever change the DBMS you're running, your use of the DBI doesn't change.

这篇关于如何获取mysql以将DateTime输出为儒略日数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆