Collections:
DATEDIFF() - Difference of Two Dates
How to calculate the difference between two dates using the DATEDIFF() function?
✍: FYIcenter.com
DATEDIFF(from_date, to_date) is a MySQL built-in function that
calculates the difference from one date to another.
For example:
SELECT DATEDIFF('2022-12-31 23:59:59','2022-12-30');
-- +----------------------------------------------+
-- | DATEDIFF('2022-12-31 23:59:59','2022-12-30') |
-- +----------------------------------------------+
-- | 1 |
-- +----------------------------------------------+
SELECT DATEDIFF('2022-11-30 23:59:59','2022-12-31');
-- +----------------------------------------------+
-- | DATEDIFF('2022-11-30 23:59:59','2022-12-31') |
-- +----------------------------------------------+
-- | -31 |
-- +----------------------------------------------+
Reference information of the DATEDIFF() function:
DATEDIFF(from_date, to_date): int Subtracts to_date from from_date and returns the difference in days. Arguments are date or date-and-time expressions and only the date parts are used in the calculation. Arguments, return value and availability: from_date: Required. The date to be subtracted from. to_date: Required. The date to be subtracted. int: Return value. The difference in days. Available since MySQL 4.
⇒ DATE_ADD() - Adding Date/Time Interval
2023-11-17, 1022🔥, 0💬
Popular Posts:
How To Convert Numeric Values to Integers in SQL Server Transact-SQL? Sometimes you need to round a ...
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...
How To Start MySQL Server in MySQL? If you want to start the MySQL server, you can run the "mysqld" ...
How To Change the Name of a Database User in SQL Server? If you want to change the name of an existi...
How To Round a Numeric Value To a Specific Precision in SQL Server Transact-SQL? Sometimes you need ...