如何将 "June 20, 2019" 之类的字符串转换为日期格式以选择日期范围
How to convert String like "June 20, 2019" to Date format in order to Selct a date Range
我有一个 Access table,其中包含如下字符串:
Date Created Date Modified
January 31, 2019 January 31, 2019
March 08, 2019 March 09, 2019
April 19, 2019 April 23, 2019
我希望能够使用 sql 查询 select 2 个日期之间的日期范围。
我正在使用 Jet4.0
引擎和 VB6
。
非常感谢任何帮助
我试过这个:
但这不会删除任何记录。
Set cijb = DBEngine.Workspaces(0).OpenDatabase(PathCIJB())
DELETE Job.* FROM Job WHERE(Job.DateModified >= 'January 03, 2019' ) AND
(Job.DateModified <= 'February 05, 2019' )
Set rs = cijb.OpenRecordset(sql, dbOpenSnapshot)
我希望删除所有修改过的记录,例如来自
March 09, 2019
至 April 23, 2019
你比较字符串与字符串。 'J' 出现在 'F' 之前没有条件,所以 WHERE
总是 false
.
比较之前你应该通过CDate
函数进行显式转换:
CDate recognizes date formats according to the locale setting of your
system. The correct order of day, month, and year may not be
determined if it is provided in a format other than one of the
recognized date settings. In addition, a long date format is not
recognized if it also contains the day-of-the-week string.
还有运行SQL命令查询你不能用OpenRecordset
:
Set cijb = DBEngine.Workspaces(0).OpenDatabase(PathCIJB())
cijb.Execute "DELETE Job.* FROM Job " & _
"WHERE (CDate(Job.DateModified) >= CDate('January 03, 2019')) AND (CDate(Job.DateModified) <= CDate('February 05, 2019'));"
我有一个 Access table,其中包含如下字符串:
Date Created Date Modified
January 31, 2019 January 31, 2019
March 08, 2019 March 09, 2019
April 19, 2019 April 23, 2019
我希望能够使用 sql 查询 select 2 个日期之间的日期范围。
我正在使用 Jet4.0
引擎和 VB6
。
非常感谢任何帮助
我试过这个:
但这不会删除任何记录。
Set cijb = DBEngine.Workspaces(0).OpenDatabase(PathCIJB())
DELETE Job.* FROM Job WHERE(Job.DateModified >= 'January 03, 2019' ) AND
(Job.DateModified <= 'February 05, 2019' )
Set rs = cijb.OpenRecordset(sql, dbOpenSnapshot)
我希望删除所有修改过的记录,例如来自
March 09, 2019
至 April 23, 2019
你比较字符串与字符串。 'J' 出现在 'F' 之前没有条件,所以 WHERE
总是 false
.
比较之前你应该通过CDate
函数进行显式转换:
CDate recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the day-of-the-week string.
还有运行SQL命令查询你不能用OpenRecordset
:
Set cijb = DBEngine.Workspaces(0).OpenDatabase(PathCIJB())
cijb.Execute "DELETE Job.* FROM Job " & _
"WHERE (CDate(Job.DateModified) >= CDate('January 03, 2019')) AND (CDate(Job.DateModified) <= CDate('February 05, 2019'));"