DataTable.Select日期格式问题 [英] DataTable.Select date format problem

查看:605
本文介绍了DataTable.Select日期格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DataTable.Select过滤日期范围的数据,我的条件字符串是:

 CreatedOn> ; ='03/11/2009 00:00:00'AND CreatedOn< ='03/11/2009 23:59:00'

此过滤器不返回任何行(即使可以在未过滤的数据表中看到匹配的行)。但是,如果我将条件改为(注意日/月转置),请注意:

 CreatedOn> ='11 / 03/2009 00:00:00'AND CreatedOn< ='11/03/2009 23:59:00'

预期的数据过滤器。显然,这似乎是一个日期本地化问题,是否有一种简单的格式化日期来避免这个问题?

解决方案

使用标准的ISO格式datetime(11月3日):

 CreatedOn> ='2009-11-03 00: 00:00'AND CreatedOn< ='2009-11-03 23:59:00'

其实如果你想要11月3日创建的所有记录,你应该这样做,因为你也希望在最后一刻创建的记录,例如23:59:30:

 CreatedOn> ='2009-11-03'AND CreatedOn<'2009-11 -04'

有一个快速参考 here


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?

解决方案

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'"

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'"

There's a quick reference here

这篇关于DataTable.Select日期格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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