在 Access 数据库中,你可以使用 Now()
函数来获取当前日期和时间,或者使用 Date()
仅获取当前日期。具体用法如下:
1. 在 SQL 语句中使用
SELECT Now() AS CurrentDateTime;
或
SELECT Date() AS CurrentDate;
2. 在 VBA 代码中使用
如果你在 VBA 代码中想获取当前时间,可以这样写:
Dim currentTime As Date
currentTime = Now()
MsgBox "当前时间是: " & currentTime
3. 在查询中使用
如果你要在查询中插入当前时间,可以这样:
INSERT INTO Orders (OrderDate) VALUES (Now());
4. 在表的默认值中使用
如果某个字段(如 CreateTime
)需要默认填充当前时间,可以在该字段的 默认值 里设置 Now()
。
这些方法都能帮助你在 Access 数据库中获取当前时间。