SQL数据库中getDate()函数

SQL数据库中getDate()函数,第1张

SQL数据库中getDate()函数作用是获取系统当前时间

1、函数语法:getdate()

2、返回类型:返回datetime型时间

3、例:select

getdate()

4、该时间是数据库服务器的时间,那么如果连接的是远程数据库,获取的时间可能和本机当前时间有差异。

扩展资料:

列:--取时间的某一个部分

select

datepart(yy,getdate())

--year

select

datepart(mm,getdate())

--month

select

datepart(dd,getdate())

--day

select

datepart(hh,getdate())

--hour

select

datepart(mi,getdate())

--min

select

datepart(ss,getdate())

--sec

参考资料来源:百度百科-getdate

(1)在SQL中用法

函数名: getdate

功 能::GETDATE() 函数从 SQL Server 返回当前的时间和日期。

例子:SELECT GETDATE() AS CurrentDateTime

结果: CurrentDateTime

2008-12-29 16:25:46.635

--取时间的某一个部分

select datepart(yy,getdate()) --year

select datepart(mm,getdate()) --month

select datepart(dd,getdate()) --day

select datepart(hh,getdate()) --hour

select datepart(mi,getdate()) --min

select datepart(ss,getdate()) --sec

(2)在C中用法

函数名: getdate

功 能: 取DOS日期

用 法: void getdate(struct *dateblk)

程序例:

#include<stdio.h>

#include <dos.h>

int main(void){

struct date d

getdate(&d)

printf("The current year is: %d\n",d.da_year)

printf("The current day is: %d\n",d.da_day)

printf("The current month is: %d\n",d.da_mon)

return 0

}

备注:在VC++6.0中运行上述程序不能通过,原因是此版本的<dos.h>中不包含getdate函数。但在TroboC 中运行可以通过。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9775997.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存