Date and Time Functions

This section describes some commonly used date and time functions like, CURRENT_DATE(), CURRENT_TIME(), and EXTRACT().

"CURRENT_DATE()" - Returns the current date.

"CURRENT_TIME()" - Returns the current time.

"CURRENT_TIMESTAMP()" - Returns the current date and time.

"EXTRACT(field_name FROM date_time)" - Returns a numeric value of the specified field name of the specified date and time value.

Examples of date and time functions, DateTimeFunctions.sql:

-- DateTimeFunctions.sql
-- Copyright (c) 2015, HerongYang.com, All Rights Reserved.
--
SELECT CURRENT_TIME();
SELECT EXTRACT(HOUR FROM CURRENT_TIME());
SELECT EXTRACT(MONTH FROM TIMESTAMP'1999-02-28 10:20:30');

Output:

CURRENT_TIME()
21:38:37
EXTRACT(HOUR FROM CURRENT_TIME())
21
EXTRACT(MONTH FROM TIMESTAMP'1999-02-28 10:20:30')
2

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

Commonly Used Functions

 Flow Control Functions

 Character String Functions

 Numeric Functions

Date and Time Functions

 Cast Function

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version