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
Three tables are connected. Field a of table A co...
We don't need to elaborate too much on the ad...
When executing yum in dockerfile or in the contai...
When writing a web project, I encountered an intr...
Container auto-start Docker provides a restart po...
Add inline styles to the required links: Copy code...
This article example shares the specific code of ...
The fastest way to experience the latest version ...
Table of contents 1. Open WeChat Pay 1.1 Affiliat...
Table of contents 1. What is multi-instance 2. Pr...
Table of contents 1. JavaScript can change all HT...
Sublime Sublime Text is a code editor (Sublime Te...
50 lines of code to change 5 skin colors, includi...
In web front-end development, it is inevitable to ...
Docker error 1. Check the cause docker logs nexus...