HQL 日期函式

2021-10-07 17:43:36 字數 2413 閱讀 9395

1 current_date():返回當前日期

select

current_date

;# 結果:2020-07-03

2 current_timestamp():返回當前時間

select

current_timestamp()

;# 結果:2020-07-03 12:42:25.725

3 add_months(start_date, num_months):返回開始日期後num_months的日期

select

current_date

;# 結果:2020-07-03

select add_months(

current_date,5

);# 結果:2020-12-03

4 date_add(start_date, num_days):返回開始日期後的num_days的日期

select

current_date

;# 結果:2020-07-03

select date_add(

current_date,10

);# 結果:2020-07-13

5 date_sub(start_date, num_days):返回開始日期前num_days的日期

select

current_date

;# 結果:2020-07-03

select date_sub(

current_date,10

);# 結果:2020-06-23

select

current_date

;# 結果:2020-07-03

select next_day(

current_date

,'firday'

);

7 dayofmonth(date):返回date日期在當月的第幾天

select

current_date

;# 結果:2020-07-03

select dayofmonth(

current_date);

# 結果:3

8 weekofyear(date):返回date日期在當年的第幾周

select

current_date

;# 結果:2020-07-03

select weekofyear(

current_date);

# 結果:27

9 minute/hour/day/month/year

select

minute

(current_timestamp()

);# 結果:37

10 date_format(date/timestamp/string, fmt):將日期/時間戳/string轉換為日期格式fmt指定格式的字串值。

select

current_date

;# 結果:2020-07-03

select date_format(

current_date

,'yyyy/mm/dd'

);

11 datediff(date1, date2):返回date1和date2之間的時間間隔

select

current_date

;# 結果:2020-07-03

select datediff(

current_date

,'2020-03-02');

# 結果:122

12 to_unix_timestamp(date[, pattern]):返回unix時間戳

select

current_date

;# 結果:2020-07-03

select to_unix_timestamp(

current_date);

# 結果:1593705600

13 from_unixtime(unix_time, format):使用指定格式返回unix時間

select from_unixtime();

```14 to_date(

datetime

):將字串轉化為日期格式``

`sql

select to_date(

'2020-01-02 11:11:11');

# 結果:2020-01-02``

`

HQL函式彙總

criteria查詢對查詢條件進行了物件導向封裝,符合程式設計人員的思維方式,不過hql hibernate query language 查詢提供了更加豐富的和靈活的查詢特性,因此hibernate將hql查詢方式立為官方推薦的標準查詢方式,hql查詢在涵蓋criteria查詢的所有功能的前提下,...

HQL常用函式

criteria查詢對查詢條件進行了物件導向封裝,符合程式設計人員的思維方式,不過hql hibernate querylanguage 查詢提供了更加豐富的和靈活的查詢特性,因此hibernate將hql查詢方式立為官方推薦的標準查詢方式,hql查詢在涵蓋criteria查詢的所有功能的前提下,提...

HQL筆記 常用函式

substrign 要擷取的字元屬性字段,開始位置,擷取長度 字元擷取 trim 字串物件屬性列 去掉兩端的空格 lower 字串物件屬性列 轉換小寫 upper 字串物件屬性列 轉換大寫 length 欄位名 字元長度 current date 資料庫當前日期 current time 資料庫當前...