SQL method for calculating timestamp difference Overview Sometimes we need to find certain records by time, for example: calculate the records one hour before the sales time. Use code to calculate the time and then pass it to SQL We can use JAVA code to calculate the time first, and then pass it to the SQL statement to avoid using MYSQL functions. public long xxxx(long sellTimeFrom){ Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(sellTimeFrom)); calendar.set(Calendar.HOUR_OF_DAY,calendar.get(Calendar.HOUR_OF_DAY) - 1); return calendar.getTime().getTime(); } This will calculate the time one hour before the sale time. Then pass it into the SQL statement where you write the code snippet. In this way, if the sales time field has an index, the index can be used. Thank you for reading, I hope it can help you, thank you for your support of this site! You may also be interested in:
|
<<: Problems and solutions of using TweenMax animation library in angular
This article example shares the specific code of ...
In development projects, we can monitor SQL with ...
Table of contents 1. Overview 1.1 Definition 1.2 ...
Rendering Commonly used styles in Blog Garden /*T...
When I used g++ to compile the cpp file for the f...
In actual development, the primary key of MySQL c...
1. Go to the official website to download the ins...
Table of contents Vue2.x Usage Global Registratio...
I have recently been developing a visual operatio...
Preface The reduce() method receives a function a...
Recently I saw a barrage effect on B station call...
Table of contents 1. Build the operating environm...
To merge the following two files, merge them toge...
A simple record of the database startup problems ...
Pseudo-arrays and arrays In JavaScript, except fo...