sql如何讀取系統日期和時間

時間 2021-09-08 03:19:00

1樓:

getdate() 函式從 sql server 返回當前的時間和日期。

使用下面的 select 語句:

select getdate() as currentdatetime

結果:currentdatetime

2008-12-29 16:25:46.635

註釋:上面的時間部分精確到毫秒。

例子 2

下面的 sql 建立帶有日期時間列 (orderdate) 的 "orders" 表:

create table orders

(orderid int not null primary key,

productname varchar(50) not null,

orderdate datetime not null default getdate()

)請注意,orderdate 把 getdate() 規定為預設值。結果是,當您在表中插入新行時,當前日期和時間自動插入列中。

現在,我們希望在 "orders" 表中插入一條記錄:

insert into orders (productname) values ('computer')

"orders" 表將成為這樣:

orderid productname orderdate

1 'computer' 2008-12-29 16:25:46.635

2樓:匿名使用者

select getdate()得到當前日期。

在表欄位的預設值寫上getdate()就可以得到預設的系統日期,插入資料的時候就不用插入這個欄位了。

3樓:

請採用下列系統函式 getdate(),如下指令碼所示:

select getdate() as [當前日期及時間]

請採納!

4樓:一騎當後

sql讀取系統日期和時間的方法如下:

--獲取當前日期(如:yyyymmdd)

select convert (nvarchar(12),getdate(),112)

--獲取當前日期(如:yyyymmdd hh:mm:ss)

select getdate()

--獲取當前日期(如:yyyy-mm-dd)

select datename(year,getdate())+'-'+datename(month,getdate())+'-'+datename(day,getdate())

--獲取當前日期(如:yyyy/mm/dd)

select datename(year,getdate())+'/'+datename(month,getdate())+'/'+datename(day,getdate())

--獲取幾種日期

select datename(year,getdate()) --年份(yyyy)

select datename(yy,getdate())

select datename(mm,getdate()) --月份

select datename(dd,getdate()) --日期

select datename(hh,getdate()) --獲取小時

select datename(mi,getdate()) --獲取分鐘

select datename(second,getdate()) --獲取秒

select datename(week,getdate()) --獲取當前星期(周)是這一年中的第幾個星期(周)

select datename(weekday,getdate()) --星期幾

5樓:匿名使用者

資料庫系統都會有這種函式,比如ms sqlserver 的 getdate()

6樓:匿名使用者

getdate()或date()函式可以得到日期+時間,如只需要日期,用convert轉換select convert(char(8),getdate(),108) as yourtime, convert(char(10),getdate(),120) as yourdate, left(convert(char(10),getdate(),120),4) as youryear

7樓:匿名使用者

selece getdate()

這就是系統當前時間和日期

8樓:匿名使用者

access是now(),sql是getdate()。

9樓:匿名使用者

select getdate()

SQL時間格式轉換,sql日期格式轉換

舉例如下 select convert varchar 10 getdate 120 2006 05 12 select convert varchar,getdate 120 2006 05 12 11 06 08 select replace replace replace convert va...

時間日期怎麼調,時間 日期如何調?

步驟bai 1,在win10桌面點選工作列最右端的時間顯du示視窗,在彈出選單中選擇zhi 日期與時間設定dao 2,開啟日期與時間設定視窗後,預設狀態下更改日期與時間的選項為灰色,不可選擇,因此需要將上方 自動設定時間 置於關閉狀態。3,將自動設定時間滑動鍵向左撥動關閉自動設定後,再點選下方的更改...

電腦如何設定時間日期,電腦日期時間怎麼設定

您好,方法。開啟電腦,點選 開始 按鈕進去。在頁面中,找到 控制版面 點選進去。在頁面中找到 日期和時間 然後點選進去。然後在頁面中看到 更改日期和時間 和 更改時區 可以先進行時區的更改在更改日期和時間。點選 更改時區 進去,更正為您所在地的時區,正常我們的都是用北京時間的。更正好時區後,返回更改...