TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

MySQL

MySQL NOW Function

Overview

In this tutorial, we will learn about MySQL NOW Function with some examples. The NOW() Function returns the current date and time. The result is displayed in ‘YYYY-MM-DD HH:MM:DD’ format.

Syntax

The general syntax for the NOW() function is:

NOW()

Examples

Simple example of the function usage are as follows:

mysql> SELECT NOW();
+———————+
| NOW() |
+———————+
| 2022-06-12 22:11:20 |
+———————+
1 row in set (0.00 sec)

mysql> SELECT NOW() + 7;
+—————-+
| NOW() + 7 |
+—————-+
| 20220612223947 |
+—————-+
1 row in set (0.00 sec)

IGNORE_SPACE

By default, there must be no whitespace between a function name and the parenthesis. However, we can change this default behavior by enabling the SET sql_mode to cause whitespace after the function name to be ignored.

This example contains a whitespace between a function name and the parenthesis. This leads to an error
message as shown below:

mysql> SELECT NOW ();

ERROR 1630 (42000): FUNCTION world.NOW does not exist. Check the ‘Function Name Parsing and Resolution’ section in the Reference Manual

mysql> SET sql_mode=’IGNORE_SPACE’;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT NOW ();
+———————+
| NOW () |
+———————+
| 2022-06-15 14:12:48 |
+———————+
1 row in set (0.01 sec)

 

NOW Function with whitespace

Input to another Function

The NOW() Function’s output can be the input of another MySQL function. We can also invoke this function in other date functions. For example, to know the weekday that is from 100 days from now.

mysql> SELECT NOW() +INTERVAL 100 DAY;
+————————-+
| NOW() +INTERVAL 100 DAY |
+————————-+
| 2022-09-20 22:31:10 |
+————————-+
1 row in set (0.00 sec)

mysql> SELECT DAYNAME(NOW() +INTERVAL 100 DAY);
+———————————-+
| DAYNAME(NOW() +INTERVAL 100 DAY) |
+———————————-+
| Tuesday |
+———————————-+
1 row in set (0.00 sec)

MySQL NOW() Function

—

MySQL Tutorials

MySQL Tutorials on this website:

https://www.testingdocs.com/mysql-tutorials-for-beginners/

For more information on MySQL Database:

https://www.mysql.com/

Related Posts

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

‹ Launch MySQL Workbench on Windows 11› Download & Install MySQL on Windows 11

Recent Posts

  • Update draw.io on Windows
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com