如何从文本字段的两个日期之间的访问中选择数据 [英] how to select data from access between two dates that is text field

查看:78
本文介绍了如何从文本字段的两个日期之间的访问中选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的先生/女士



我的数据库字段日期是文本归档如何选择日期范围内的数据。它不显示整个数据。在另一个表中我有几个月的文本字段,如10,11和选择不检索整个数据

Dear Sir/Madam

i have database field date that is text filed how to select data in date range .it does not show whole data. same in another table i have months text field like 10,11 and selection does not retrieve whole data

推荐答案

简单的答案是:不要将日期存储为文本字段。

当你这样做时,你尝试做的任何比较都是字符串比较,这意味着它们是逐个字符地进行的,而不同的第一个字符控制着整个比较。 br />
所以01/02/2013​​在10/01/2012之前,甚至在01/03/1066之前



如果将数据保存为字符串,每次尝试使用它们时都会遇到这些问题(以及其他问题),并且在空间方面非常浪费。使用DateTime列代表意味着问题全部消失,你可以这样做:

The simple answer is: don't store dates as text fields.
When you do, any comparisons that you try to do are string comparisons, which means they are carried out on a character by character basis, and the first character that is different controls the whole comparison.
So "01/02/2013" is before "10/01/2012" and even before "01/03/1066"

If you keep data stored as strings, you will get these problems (and other ones) every time you try to use them, as well as being very wasteful in terms of space. Using a DateTime column instead means that the problems all go away, and you can do this:
SELECT * FROM MyTable WHERE MyDate BETWEEN #2014-01-01# AND #2014-02-01#



如果不这样做,那么你将必须转换每次你想要使用它们,这可能会引发很多其他问题,这取决于谁输入你的系统日期和他们输入的格式...



BETWEEN在查询表达式中恢复,日期用#而不是引号分隔 - OriginalGriff [/ edit]


If you don't then you will have to convert each time you want to use them, and that can raise a lot of other problems, depending on who entered the dates into your system and what format(s) they were entered in...

[edit]BETWEEN restored in query expression, dates delimited with # instead of quote - OriginalGriff[/edit]


这是将日期存储为的缺点文本。数据库将执行文本语义,您将很难过滤记录。将字段转换为日期字段,数据库将开始执行日期语义,并将自动开始为您处理不同的日期格式。
That is the disadvantage of storing dates as text. The database will perform text semantics and you'll have a tough time filtering records. Convert the field to a date field and the database will start performing date semantics and will automatically start handling different date formats for you.


这篇关于如何从文本字段的两个日期之间的访问中选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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