MySQL MAKETIME() Function

MySQL MAKETIME() function; In this tutorial, i am going to show you MySQL maketime() function with the help of examples.

MySQL MAKETIME() Function

MySQL MAKETIME() makes and returns a time value from a given hour, minute and seconds. The value of hour may be greater than 24 but the value of minutes and second greater than 59 return NULL. Indicates an hour. Indicates minutes.

Syntax of MySQL MAKETIME() Function

The syntax of MAKETIME() function is:

 MAKETIME(hour,minute,second);

Here we demonstrate :

  • The hour is the hour part.
  • The minute is the minutes part.
  • Second is the seconds part.

Example 1 – MySQL MAKETIME() Function

Let’s take an example using the maketime() function; as follows:

SELECT MAKETIME(10,35,17);

Output-1

+--------------------+
| MAKETIME(10,35,17) |
+--------------------+
| 10:35:17           |
+--------------------+

Example 2 – MySQL MAKETIME() Function

Let’s take an example using the maketime() function with a fractional part; as follows:

SELECT MAKETIME(10,35,17.123456);

Output-2

+---------------------------+
| MAKETIME(10,35,17.123456) |
+---------------------------+
| 10:35:17.123456           |
+---------------------------+

Example 3 – MySQL MAKETIME() Function

Part of the hour is not limited to 0 to 23 limits. Time can probably represent the time or time elapsed between two incidents; as follows:

SELECT MAKETIME(100,35,17);

Output-3

+---------------------+
| MAKETIME(100,35,17) |
+---------------------+
| 100:35:17           |
+---------------------+

Example 4 – MySQL MAKETIME() Function

However, this does not apply to the minute part. It should be within range 0 to 59; as follows:

SELECT 
    MAKETIME(10,-1,17),
    MAKETIME(10,60,17);

Output-4

+--------------------+--------------------+
| MAKETIME(10,-1,17) | MAKETIME(10,60,17) |
+--------------------+--------------------+
| NULL               | NULL               |
+--------------------+--------------------+

Example 5 – MySQL MAKETIME() Function

However, this also does not apply to the second part. It should be within range 0 to 59; as follows:

SELECT 
    MAKETIME(10,35,-1),
    MAKETIME(10,35,60);

Output-5

+--------------------+--------------------+
| MAKETIME(10,35,-1) | MAKETIME(10,35,60) |
+--------------------+--------------------+
| NULL               | NULL               |
+--------------------+--------------------+

Conclusion

MySQL MAKETIME() Function tutorial, you have learned how to use MySQL MAKETIME() function with various examples.

Be First to Comment

Leave a Reply

Your email address will not be published.