MySQL時間 日期 時區函式和計算函式

2021-10-07 01:30:37 字數 1272 閱讀 8387

1.獲得當前日期+時間(date + time)函式:now()sysdate()

sysdate() 日期時間函式跟 now() 類似,不同之處在於:now() 在執行開始時值就得到了, sysdate() 在函式執行時動態得到值,不太常用。

2.獲取當前日期current_date

3.獲取當前時分秒:current_time

4. 獲得當前時間戳函式:current_timestamp, current_timestamp()

select

now(),

current_date

as 當前年月日,

current_time

as 當前時分秒,

current_timestamp

1.date/time to str(日期/時間轉換為字串)函式:date_format(date,format),

它是 str_to_date(str,format) 函式的 乙個逆轉換。

select str_to_date(

'08/09/2008'

,'%m/%d/%y');

-- 2008-08-09

select str_to_date(

'08/09/08'

,'%m/%d/%y');

-- 2008-08-09

1.為日期增加乙個時間間隔:date_add()

2.mysql 為日期減去乙個時間間隔:date_sub()

mysql date_sub() 日期時間函式 和 date_add() 用法一致,不再贅述。

3.timediff(time1,time2):兩個日期相減 time1 - time2,返回 time 差值。

注意:timediff(time1,time2) 函式的兩個引數型別必須相同。

4. 時區轉換函式convert_tz(dt,from_tz,to_tz)

select convert_tz(

'2008-08-08 12:00:00'

,'+08:00'

,'+00:00');

-- 2008-08-08 04:00:00

mysql時間日期函式

now current timestamp 當前日期時間 current date 當前日期 current time 當前時間 date yyyy mm dd hh ii ss 獲取日期部分 time yyyy mm dd hh ii ss 獲取時間部分 date format yyyy mm d...

mysql時間日期函式

now current timestamp 當前日期時間 current date 當前日期 current time 當前時間 date yyyy mm dd hh ii ss 獲取日期部分 time yyyy mm dd hh ii ss 獲取時間部分 date format yyyy mm d...

mysql 時間日期函式

dayofweek date dayofweek 返回日期date是星期幾 1 星期天,2 星期一,7 星期六,odbc標準 mysql select dayofweek 1992 03 03 3 weekday date weekday 返回日期date是星期幾 0 星期一,1 星期二,6 星期天...