作者:s350350350 | 来源:互联网 | 2023-02-09 17:17
IstoredatesasStringinmydatabase,inthisformat:我将日期作为字符串存储在我的数据库中,格式如下:YYYY-MM-DDHH:MM:S
I store dates as String
in my database, in this format:
我将日期作为字符串存储在我的数据库中,格式如下:
YYYY-MM-DD HH:MM:SS
which is one of supported formats (http://www.sqlite.org/lang_datefunc.html). Now I want to compare these stored dates (well, strings) with another dates. My dates are stored in column column_date
, so I'm trying this:
这是一种受支持的格式(http://www.sqlite.org/lang_datefunc.html)。现在我想将这些存储的日期(嗯,字符串)与其他日期进行比较。我的日期存储在列column_date中,所以我正在尝试:
SELECT * FROM MyTable
WHERE
(Date(column_date) >= Date (2000-01-01) AND Datetime(column_date) <= Datetime (2050-01-01))
As i read documentation, The date and time functions use a subset of IS0-8601 date and time formats. The date() function returns the date in this format: YYYY-MM-DD.
so I suppose, I'm doing it right - I create date from stored string and compare it with date created from another strings.
当我阅读文档时,date和time函数使用IS0-8601日期和时间格式的子集。函数的作用是:返回日期。我想,我做对了,我从存储的字符串中创建日期,并将它与从其他字符串中创建的日期进行比较。
But it doesn't work, even when column_date
is date from this year, and as u can see the start and end dates are very benevolent. Tried also this (used datetime instead of date):
但它不起作用,即使当column_date是今年的日期,当u可以看到开始和结束日期是非常仁慈的。还尝试了这个(使用datetime而不是日期):
SELECT * FROM MyTable
WHERE
(datetime(column_date) >= Date (2000-01-01) AND datetime(column_date) <= Datetime (2050-01-01))
and this (use between instead of <= and >=)
这个(用between而不是<=和>=)
SELECT * FROM MyTable
WHERE
(Date(column_date) between Date (2000-01-01) AND Datetime (2050-01-01))
and all other possible combinations. What the hell I'm doing wrong, am I stupid, or the documentaion lies, or I missed something very important? Trying to find solution few hours, but nothing works...
以及所有其他可能的组合。我到底做错了什么,我是愚蠢的,还是文件上的谎言,还是我错过了一些非常重要的东西?试着找几个小时的解决方案,但是什么都不做……
5 个解决方案