Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

MySQL TO_SECONDS Function

by suresh

MySQL TO_SECONDS function is one of the MySQL Date Functions, which returns the number of seconds from year 0 to the user given date or date and time. The syntax of the TO_SECONDS() Function in MySQL is as shown below:

TO_SECONDS(date or expression);

MySQL TO_SECONDS function Example

The following MySQL examples help you understand the use of the To seconds function. Here, we are returning the number of seconds from 0 to different date values.

SELECT TO_SECONDS('2018-01-02');

SELECT TO_SECONDS('2018-12-31');

SELECT TO_SECONDS('2018-12-31 10:22:30');

OUTPUT

MySQL TO_SECONDS Function 1

MySQL TO_SECONDS Example 2

In this Date Function example, we are using NOW, CURDATE, and UTC_TIMESTAMP along with some addition operation inside this TO_SECONDS function. It means we are using the Date and time value in MySQL String format.

SELECT TO_SECONDS(NOW()), TO_SECONDS(NOW() + 25);

SELECT TO_SECONDS(CURDATE()), TO_SECONDS(CURDATE() + 2);

SELECT TO_SECONDS(UTC_TIMESTAMP());

OUTPUT

MySQL TO_SECONDS Function 2

Let us see another example of the MySQL To_Seconds function. This time, we are using the YYYYMMDD and YYMMDD formats as the date argument. From the below, 95 means 1995

SELECT TO_SECONDS('20190225');

SELECT TO_SECONDS(750225);

SELECT TO_SECONDS(951231);

OUTPUT

MySQL TO_SECONDS Function 3

MySQL To seconds function throw an error if it finds the Wrong Date Or Zero date. This example shows you the same.

Within the second statement, 65 is a wrong day value.

SELECT TO_SECONDS('0000-00-00');

SELECT TO_SECONDS('2019-12-65');

SELECT TO_SECONDS('2019-12-44 10:23:98');

OUTPUT

MySQL TO_SECONDS Function 4

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy