Get the App
SLTechnology News&Howtos  ›  Database  › 

How to query today's data with mysql

Shulou Source: shulou.com Published: 2022-05-31 11:24:59 09月15日 Update

This article focuses on "how to use mysql to query today's data", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to query today's data with mysql.

In mysql, you can use select statements in conjunction with "to_days ()" and now () functions to query today's data, with the syntax "select * from table name where to_days (time field name) = to_days (now ());".

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How does mysql query today's data?

If mysql wants to query today's data, he can use the select statement to query today's data with the TO_DAYS function and the now function.

The MySQL database uses SQL SELECT statements to query data.

TO_DAYS (date)

Given a date date, returns a date number (days since 0 years).

NOW () returns the current date and time.

Grammar

NOW ()

The syntax for querying today's data is:

Select * from table name where to_days (time field name) = to_days (now ())

Expand:

Yesterday

SELECT * FROM table name WHERE TO_DAYS (NOW ())-TO_DAYS (time field name)

Tags: Data query time field function date statement grammar content learning practical deeper interest number days practicality practical simple operation tutorial database Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS OPPO Reno Docker MariaDB