您的位置首页百科知识

Access中datepart、dateserial、datediff函数

Access中datepart、dateserial、datediff函数

的有关信息介绍如下:

Access中datepart、dateserial、datediff函数

伴随着大数据时代到来,数据将会越来越多,越来越复杂,我们都知道数据库是为数据而生的,那么Access作为最简单的数据库,有哪些函数是需要掌握的,下面讲解datepart、dateserial、datediff三个函数

打开查询设计分别使用datepart、dateserial、datediff函数进行表达式的书写。仍然采用表1的时间数据进行操作:(”年: DatePart("yyyy",[时间])-1“、”月: DatePart("m",[时间])-1“、”日: DatePart("d",[时间])-1“、“新日期: DateSerial([年],[月],[日])”、”差距: DateDiff("m",[新日期],[时间])“);

具体如图

运行结果并查看核对。如图

我们发现日期有0的,但是用dateserial运行之后自动变成了上个月的31号;

SQL语句如下:

SELECT 表1.时间, 表1.姓名, 表1.数量, DatePart("yyyy",[时间])-1 AS 年, DatePart("m",[时间])-1 AS 月, DatePart("d",[时间])-1 AS 日, DateSerial([年],[月],[日]) AS 新日期, DateDiff("m",[新日期],[时间]) AS 差距

FROM 表1;