關於日期函式以及日期計算的sql總匯

2021-09-29 21:34:03 字數 1390 閱讀 5791

/*now()為獲取當前系統時間*/

select

now();

/*精確至毫秒值*/

select curdate();

/*精確至日期值*/

/*獲取時間欄位中該月的最後一天*/

select last_day(

now())

select last_day(

'2000-02-01'

)/*分別獲取日期欄位的年月日*/

select

year

(now()

);select

month

(now()

);select

day(

now())

;select

year

('日期'

)year

,month

('日期'

)month

,day

('日期'

)day

from 表名 where 條件

/*查詢表中日期欄位的天數等於13的基本資訊*/

select

*from 表名 where

day(

'日期')=

13/*查詢使用者生日在本月的使用者資訊*/

select

*from 表名 where

month

('日期')=

month

(now()

)/*計算兩個日期之間的相差天數,引數為起始時間,引數二為結束時間*/

select timestampdiff(

day,

'2019-10-23'

,now()

)/*計算兩個日期之間的相差月數,引數為起始時間,引數二為結束時間*/

select timestampdiff(

month

,'2019-10-23'

,now()

)/*計算兩個日期之間的相差年數,引數為起始時間,引數二為結束時間*/

select timestampdiff(

year

,'2016-11-23'

,now()

)/*查詢員工入職時間大於三個月的員工資訊*/

select

*from 表名 where timestampdiff(

month

,'日期'

,now()

)>

3/*查詢員工入職大於3年的員工資訊*/

select

*from 表名 where

year

(now()

)-year

('日期'

)>=

3

Oracle單行函式以及日期計算的方式

單行函式 字元型別單行函式 lower 列名 upper 列名 查詢employees表last name列中包含a 不區分大小寫 員工的last name select last name from empolyees where upper last name like a substr 列名,...

sql日期有關函式以及oracle日期有關函式

sql日期有關函式以及oracle日期有關函式 sql日期函式 dateadd 在向指定日期加上一段時間的基礎上,返回新的 datetime 值。dateadd datepart number,date 日期部分 縮寫 year yy,yyyy quarter qq,q month mm,m day...

日期類函式(計算日期)

includeusing namespace std int runnian int year 判斷該年是否是閏年 int riqi int month,int year 因為每個月的的天數不一樣,所以用乙個函式進行判斷 else day 30 else return day class date ...