How can SQL query get today's 00:00:00 to today's 23:59:59 seconds? (Fuzzy query of time type)

When refactoring the computer room, you need to query the bill for a certain day, and use the "date" as the condition to query all the data for that day, then how to get the time period of the day?

Method 1: Between...and...

The BETWEEN operator is used in the WHERE clause to select the data range between two values.

First get two time nodes:

dtp1.Value = DateTime.Parse(DateTime.Now.Date.ToString() + " 00:00:00");
dtp2.Value = DateTime.Parse(DateTime.Now.Date.ToString() + " 23:59:59");

SQL statement:

select * from table1 where Date between 'dtp1' and 'dtp2'";

Method 2: Fuzzy query of time type, you can query a certain day at will

@date1 = date.ToString("yyyy-MM-dd")

select * from table1 where convert(varchar,Date,120) LIKE @date1+'%';

Note: When using the fuzzy query of the time type, you need to convert the time type to a string type

The above content is my personal understanding. If you have any questions, please comment below!

 

Guess you like

Origin blog.csdn.net/TGB_Tom/article/details/112431369