SQLite DATETIME函数中的“ -1月”是否“已损坏”? [英] Is the '-1 month' in SQLite DATETIME function 'broken'?

查看:63
本文介绍了SQLite DATETIME函数中的“ -1月”是否“已损坏”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用DATETIME函数进行一些算术运算时,我发现以下行为:

When using the DATETIME function to do some arithmetic, I've found the following behaviour:

选择DATETIME('now','-1 month','月初))

预期:2011-02-01 00:00:0

结果:2011-03-01 00:00:0-失败

select DATETIME('now', '-1 month', 'start of month')
expected: 2011-02-01 00:00:0
result: 2011-03-01 00:00:0 - Fail

选择DATETIME('now','-2 month','month of month')

预期:2011-01-01 00:00:0

结果:2011-01-01 00:00:0-好的

select DATETIME('now', '-2 month', 'start of month')
expected: 2011-01-01 00:00:0
result: 2011-01-01 00:00:0 - Ok

这似乎只是从昨天开始才发生的,因此我的集成测试。我的猜测是减去的月份是以天为单位计算的,并且以某种方式使用了上一个完整月份(而不是当前月份)中的天数。上一个完整月(2月为28天,因此为结果)

This only appears to be happening since yesterday, my integration tests picked up on this. My guess is that the month that is substracted is calculated in days and that somehow the number of days in the last full month is used (not the current). The last full month, february featured 28 days, hence the result)

通过更改DATETIME函数的输入顺序可以轻松解决此问题,例如:DATETIME('现在,月初,-1月),但仍然是棘手的行为,并可能导致错误被忽略。

This is easily resolved by changing the order of input to the DATETIME function, like so: DATETIME('now', 'start of month', '-1 month'), but still it is tricky behaviour and likely to result in bugs that get unnoticed.

我正在使用System.Data.SQLite.DLL /版本1.0.66.0 / 2010年4月18日

I am using System.Data.SQLite.DLL / version 1.0.66.0 / Apr 18, 2010

还有其他人发现此行为吗?这是一个已知的错误?还是我做错了?

Anybody else found this behaviour? Is this a (known) bug? Or am I 'doing it wrong'?

推荐答案

现在减一月= 2月30日= 3月2日。然后月初为您提供三月初。这可能不是任何人想要的行为,但这是文档所描述的:请转到 http:// www。 sqlite.org/lang_datefunc.html 并搜索渲染工作。

now minus one month = 30th of February = 2nd of March. Then start of month gives you the start of March. This is probably not the behaviour anyone ever wants, but it's what the documentation describes: go to http://www.sqlite.org/lang_datefunc.html and search for "works by rendering".

这篇关于SQLite DATETIME函数中的“ -1月”是否“已损坏”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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