資料庫中的日期格式

2021-05-28 15:58:08 字數 2792 閱讀 2609

db2:

select timestamp('2010-06-01 00:00:00.000') from table

select date('2010-06-01 00:00:00') from table

date函式 

語法:date(arg) 

date函式返回乙個日期、時間戳、日期字串、時間戳字串中的日期。 

select date('2005-06-12 16.24.18.121212') from test    

time函式 

語法:time(arg) 

time函式返回乙個時間、時間戳或乙個時間、時間戳字串引數的時間。

select time('2005-06-12 16.24.18.121212') from test    

timestamp函式 

語法:timestamp(expres1[,expres2]) 

timestamp函式返回乙個或兩個引數中的時間戳。

select timestamp('2005-06-12 16.24.18.121212') from test    

注:如果只有乙個引數,這個引數必須是乙個時間戳或乙個時間戳字串;如果有兩個引數,第乙個引數必須是乙個日期或日期字串,第二個引數必須是乙個時間或時間戳字串。 

year函式 

語法:year(arg) 

year函式返回乙個日期、時間戳、日期字串、時間戳字串的年部分。

select year('2005-06-12') from test    

month函式 

語法:month(arg) 

month函式返回乙個日期、時間戳、日期字串、時間戳字串的月部分。

select month('2005-06-12') from test    

quarter函式 

語法:quarter(arg) 

quarter函式返回乙個日期、時間戳、日期字串、時間戳字串的季度部分。

select quarter(current date) from test    

week函式 

語法:week(arg) 

week函式返回乙個日期、時間戳、日期字串、時間戳字串的星期部分。

select week(current date) from test    

day函式 

語法:day(arg) 

day函式返回乙個日期、時間戳、日期字串、時間戳字串的日部分。

select day(current date) from test    

hour函式 

語法:hour(arg) 

hour函式返回乙個日期、時間戳、日期字串、時間戳字串的小時部分。

select hour(current time) from test    

minute函式 

語法:minute(arg) 

minute函式返回乙個日期、時間戳、日期字串、時間戳字串的分鐘部分。

select minute(current time) from test    

second函式

語法:second(arg) 

second函式返回乙個日期、時間戳、日期字串、時間戳字串的秒部分。

select second(current time) from test    

days函式 

語法:days(arg) 

days函式返回乙個日期、時間戳、日期字串、時間戳字串的日期整數表示法,從0001-01-01以來的天數。

select days(current time) from test    

dayofyear函式

語法:dayofyear(arg) 

dayofyear函式返回乙個日期、時間戳、日期字串、時間戳字串在年內的天值。

select dayofyear(current date) from test    

dayofweek函式 

語法:dayofweek(arg) 

dayofweek函式返回乙個日期、時間戳、日期字串、時間戳字串在週內的天值(從週日開始 1 到 7 )。

select dayofweek(current date) from test    

dayofweek_iso函式 

語法:dayofweek_iso(arg) 

dayofweek_iso函式返回乙個日期、時間戳、日期字串、時間戳字串在週內的天值(從周一開始 1 到 7 )。  

select dayofweek_iso(current date) from test    

dayname函式 

語法:dayname(arg) 

dayname函式返回乙個日期、時間戳、日期字串、時間戳字串是星期幾。

select dayname(current date) from test    

monthname函式 

語法:monthname(arg) 

monthname函式返回乙個日期、時間戳、日期字串、時間戳字串的月份名。

select monthname(current date) from test    

midnight_seconds函式 

語法:midnight_seconds(arg) 

midnight_seconds函式返回午夜和引數指定的時間值之間的秒數,用範圍再 0 到 86400 之間的整數值表示。

select midnight_seconds(current time) from test   

日期格式的轉換以及資料庫的日期格式

dateformat sdformat new dateformat yyyy mm dd hh mm ss 24小時制 dateformat ss new dateformat yyyy mm dd hh mm ss 12小時制 獲取明天 date date new date calendar c...

格式化資料庫日期

格式化資料庫日期。此 段將允許您輸入date引數。它將檢查date引數以檢視是否存在有效的時間部分。然後,它將格式化日期,使其無論在何處或如何使用都可以正常工作。public function formatdate byval vdtdate as date as string dim dtnull...

處理從資料庫中返回的json格式日期

用於處理json檔案返回的日期格式。格式類似 date 1470469532000 0800 它是直接從sqlserver中以資料型別為datetime的形式儲存的。序列化時也是這樣的資料格式。直接呼叫後面的formattime即可 date.prototype.format function fo...