MySQL MAKETIME() Function Examples

MySQL MAKETIME() Function Examples

LMySQL MAKETIME() function; In this tutorial, we would love to demonstrate to you how to use MySQL maketime() function with the help of its syntax and examples.

MySQL MAKETIME() Function

In MySQL, MAKETIME() function is used to returns the time from the different time parts.

Note:-
In this maketime() function, you can pass three parameters, first is hours, second is minute, and third is seconds. It will return the time value passed on this function.

Syntax

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

Let’s take the first basic example of this maketime() function. See the below:

SELECT MAKETIME(10,35,17);

Output-1

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

Example-2

Nextt, we take another example with a fractional part. Let’s see below:

SELECT MAKETIME(10,35,17.123456);

Output-2

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

Example-3

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

SELECT MAKETIME(100,35,17);

Output-3

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

Example-4

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

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

Output-4

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

Example-5

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

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

Output-5

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

Conclusion

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

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *