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日创建的所有记录,你应该这样做,因为你也想在这最后一刻,例如创建的记录二十三时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屋!