LoginSignup
5
5

More than 5 years have passed since last update.

みんなの為のMySQLまとめ(13)

Posted at

参考
http://homepage2.nifty.com/sak/w_sak3/doc/sysbrd/mysql_16.htm

■システム日付、システム時間

・current_timestamp() 関数は、システム日付(サーバ日付) を返す。

select current_date;

kobito.1424248440.715413.png
 

select current_time;

kobito.1424248595.710490.png
 

select current_timestamp;

kobito.1424248629.370256.png
 

select now();

kobito.1424248812.643063.png
 

select date_format(now(), '%y.%m.%d');

kobito.1424248950.166245.png
 

■日付切り捨て

select cast(substring(now(), 1, 10) as date);

kobito.1424249113.349813.png
 

■日付の差 (日付間隔、日付範囲)

・to_days() をうまく利用する。
(日付計算、日数計算、カレンダー計算)

select to_days(now()) - to_days('2015-02-10 00:00:00');

kobito.1424249903.793171.png
 

■日付の加算

・date_add を使用する。
(日付計算、日数計算、カレンダー計算)

select date_add(now(), interval 3 day);

kobito.1424250156.940519.png
 

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5