A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sql/addtime-function-in-mysql/ below:

MySQL ADDTIME() function - GeeksforGeeks

MySQL ADDTIME() function

Last Updated : 10 Jun, 2024

MySQL ADDTIME() function adds the specified time intervals to the given date and time. It returns the date or DateTime value after adding the time interval.

Syntax

The MySQL ADDTIME() function syntax is:

ADDTIME(expr1, expr2)

Parameter

ADDTIME() function accepts two parameters.

MySQL ADDTIME() Function Example

Let's look at some examples of the ADDTIME() function in MySQL. Learning MySQL ADDTIME function with examples, help in understanding the concept better.

Example 1

In this example, we are adding 15 seconds to the specified time using the ADDTIME function.

SELECT ADDTIME("11:34:21", "15") 
AS Updated_time ;

Output :

Example 2

In this example, we are adding 10 minutes to the specified time using the ADDTIME function.

SELECT ADDTIME("10:54:21", "00:10:00") 
AS Updated_time ;

Output :

Example 3

In this example, we are adding 12 hours with the specified datetime using ADDTIME Function.

SELECT ADDTIME("2009-02-20 18:04:22.333444", "12:00:00") 
AS Updated_time ;

Output :

Updated_time  2009-02-21 06:04:22.333444 Using ADDTIME function on Table Column Values

In this example, we will use the ADDTIME function on the values of columns.

First, let's create a table named ScheduleDetails

CREATE TABLE ScheduleDetails(
TrainId INT NOT NULL,
StationName VARCHAR(20) NOT NULL,
TrainName VARCHAR(20) NOT NULL,
ScheduledlArrivalTime TIME NOT NULL,
PRIMARY KEY(TrainId )
);

Now inserting values in the ScheduleDetails table. We will use ADDTIME function, which will denote delay in arrival timing. The value in the ExpectedArrivalTime column will be the value given by the ADDTIME function.

INSERT INTO  
ScheduleDetails (TrainId, StationName, TrainName, ScheduledlArrivalTime )
VALUES
(12345, 'NJP', 'Saraighat Express', "17:04:22");

Now, checking the ScheduleDetails table :

SELECT *, ADDTIME(ScheduledlArrivalTime, "00:10:00") 
AS ExpectedArrivalTime FROM ScheduleDetails;

Output :

TrainId StationName TrainName ScheduledlArrivalTime ExpectedArrivalTime 12345 NJP Saraighat Express 17:04:22 17:14:22 Important Points About MySQL ADDTIME() Function


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4