DataTable.Select 日期格式问题 [英] DataTable.Select date format problem
问题描述
我正在使用 DataTable.Select 在日期范围内过滤数据表,我的条件字符串是:
I'm filtering a datatable on a date range using DataTable.Select, my criteria string is:
"CreatedOn >='03/11/2009 00:00:00' AND CreatedOn <='03/11/2009 23:59:00'"
此过滤器不返回任何行(即使我可以在未过滤的数据表中看到匹配的行).但是我注意到如果我将标准更改为(注意日/月换位):
This filter returns no rows (even though I can see matching rows in the unfiltered datatable). However I notice if I change the criteria to (note the day/month transposition):
"CreatedOn >='11/03/2009 00:00:00' AND CreatedOn <='11/03/2009 23:59:00'"
数据表按预期过滤.显然,这似乎是一个日期本地化问题,是否有一种简单的方法来格式化日期以避免此问题?
The datatable filters as expected. Clearly this seems to be a date localisation issue, is there an easy way to format the date to avoid this issue?
推荐答案
像这样使用标准的 ISO 格式日期时间(对于 11 月 3 日):
Use a standard ISO format datetime like this (for 3rd Nov):
"CreatedOn >='2009-11-03 00:00:00' AND CreatedOn <='2009-11-03 23:59:00'"
事实上,如果您希望在 11 月 3 日创建所有记录,您应该这样做,因为您还希望在最后一分钟创建记录,例如23:59:30:
In fact, if you want all records created on 3rd Nov, you should really do this as you also want records created in that last minute e.g. 23:59:30:
"CreatedOn >='2009-11-03' AND CreatedOn < '2009-11-04'"
有一个快速参考这里
这篇关于DataTable.Select 日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!