SQL 仅在访问日期/时间字段中查找时间而不是日期 [英] SQL-only find time and not date in Access Date/Time field

查看:69
本文介绍了SQL 仅在访问日期/时间字段中查找时间而不是日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Access 数据库表中,某些日期/时间数据已损坏,现在仅显示时间,例如15:15.是否有任何 SQL 可以让我选择只有时间数据而没有任何日期数据的记录?

In an Access database table some Date/Time data has corrupted and now only shows a time e.g. 15:15. Is there any SQL that will allow me to select records which only have the time data and not any date data in?

我试过了,但是不行

select datetimefield
from table
WHERE IsDate(datetimefield) = 0

推荐答案

Access 没有单独的 DateTime 列(字段)类型,所以它做了两件事帮助"用户处理日期"和时间":

Access does not have separate Date and Time column (field) types, so it does two things to "help" users work with "dates" and "times":

  1. 时间正好为午夜的日期/时间值默认将仅显示为日期.

日期部分为 1899-12-30 的日期/时间值将默认显示为时间.

Date/Time values where the date part is 1899-12-30 will by default be displayed as just the time.

在这些特殊情况下,可以通过专门格式化值(使用字段或控件的 .Format 属性,或使用 Format() 函数).

In these special cases the full Date/Time information can be displayed by specifically formatting the value (using the .Format properties of fields or controls, or by using the Format() function).

因此,要选择看起来像的日期/时间值,它们只包含您会执行的时间

So, to select Date/Time values that look like they only contain times you would do

SELECT datetimevalue
FROM tablename
WHERE datetimevalue >= #1899-12-30# AND datetimevalue < #1899-12-31#

这篇关于SQL 仅在访问日期/时间字段中查找时间而不是日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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