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
Here are 10 tips on how to design better-usable w...
Detailed explanation of JDBC database link and re...
This article shares the specific code for the WeC...
This article summarizes the notes for installing ...
Preface Nginx (pronounced "engine X") i...
1. What is HTML HTML (HyperText Markup Language):...
MySQL previously had a query cache, Query Cache. ...
1. Download the virtual machine version 15.5.1 I ...
1. Element time selection submission format conve...
Table of contents Generate random numbers Generat...
About derived tables When the main query contains...
MySQL has the following logs: Error log: -log-err...
To achieve CSS screen size adaptation, we must fi...
Table of contents 1 Introduction to the new opera...
The following situations were discovered during d...