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
Table of contents 1. Features 2. Examples 3. Opti...
Chinese Tutorial https://www.ncnynl.com/category/...
Change personal account password If ordinary user...
Table of contents accomplish: Summarize: Not much...
This article example shares the specific code of ...
Basic preparation For this implementation, we nee...
After getting used to VM, switching to BOX is a l...
1. To build a PPTP VPN, you need to open port 172...
1. Introduction table_cache is a very important M...
CSS has two pseudo-classes that are not commonly ...
Tip: In MySQL, we often need to create and delete...
Copy code The code is as follows: <span style=...
Table of contents 2. Tried methods 2.1 keep-alive...
Table of contents 1. Interface effect preview 2.u...
Table of contents Method 1: Call the function dir...