![]() |
MySQL Datediff |
Berikut adalah cara menghitung antara 2 tanggal(datetime) menggunakan datediff, anda hanya tinggal perlu copas script dibawah ini dan langsung run di MySQL, hasilnya seperti diatas.
Jika ingin menambahkan fungsi bulan hanya tinggal menambahkan rumus modifikasi yang diambil dari days diatas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
@diff:=ABS( UNIX_TIMESTAMP("2021-09-31 08:00:00") - UNIX_TIMESTAMP() ) , | |
CAST(@days := IF(@diff/86400 >= 1, FLOOR(@diff / 86400 ),0) AS SIGNED) AS days, | |
CAST(@hours := IF(@diff/3600 >= 1, FLOOR((@diff:=@diff-@days*86400) / 3600),0) AS SIGNED) AS hours, | |
CAST(@minutes := IF(@diff/60 >= 1, FLOOR((@diff:=@diff-@hours*3600) / 60),0) AS SIGNED) AS minutes, | |
CAST(@diff-@minutes*60 AS SIGNED) AS seconds; |