Collections:
TIMESTAMPADD() - Incrementing Timestamp
How to increment a component of timestamp value using the TIMESTAMPADD() function?
✍: FYIcenter.com
TIMESTAMPADD(unit, interval, datetime) is a MySQL built-in function that
updates a timestamp by incrementing a component.
For example:
SELECT TIMESTAMPADD(MINUTE, 1, '2023-01-02'); -- +---------------------------------------+ -- | TIMESTAMPADD(MINUTE, 1, '2023-01-02') | -- +---------------------------------------+ -- | 2023-01-02 00:01:00 | -- +---------------------------------------+ SELECT TIMESTAMPADD(MINUTE, -1, '2023-01-02'); -- +----------------------------------------+ -- | TIMESTAMPADD(MINUTE, -1, '2023-01-02') | -- +----------------------------------------+ -- | 2023-01-01 23:59:00 | -- +----------------------------------------+ SELECT TIMESTAMPADD(WEEK, 1, '2023-02-28'); -- +-------------------------------------+ -- | TIMESTAMPADD(WEEK, 1, '2023-02-28') | -- +-------------------------------------+ -- | 2023-03-07 | -- +-------------------------------------+ SELECT TIMESTAMPADD(MONTH, 1, '2023-03-31'); -- +--------------------------------------+ -- | TIMESTAMPADD(MONTH, 1, '2023-03-31') | -- +--------------------------------------+ -- | 2023-04-30 | -- +--------------------------------------+
Reference information of the TIMESTAMPADD() function:
TIMESTAMPADD(unit, interval, datetime): moddate Adds the integer expression interval to the timestamp expression datetime. The unit for interval is given by the unit argument, which should be one of the following values: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. Arguments, return value and availability: unit: Required. The timestamp component unit keyword. interval: Required. The integer value to increment by. datetime: Required. The starting timestamp. moddate: Return value. The incremented timestamp. Available since MySQL 4.0.
Related MySQL functions:
⇒ TIMESTAMPDIFF() - Difference in Timestamp Component
⇐ TIMESTAMP() - Adding Time to Timestamp
2023-11-17, 1053🔥, 0💬
Popular Posts:
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...
How To Connect the Oracle Server as SYSDBA in Oracle? This is Step 4. The best way to connect to the...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...
Where to find answers to frequently asked questions on INSERT, UPDATE and DELETE Statements in MySQL...
How To Generate Random Numbers with the RAND() Function in SQL Server Transact-SQL? Random numbers a...