The actual project will always encounter a variety of time calculation queries and so many times is particularly troublesome before the company has a demand is roughly to query the current date and the database storage date difference, originally wrote a tool class call but finally think this is not good thinking can be solved with the function, did not expect to share the following, SQL is as follows:
Select DateDiff (' 2017-04-21 ', (select Now ()) as day, date subtraction gets the number of days, simple, get the current date is actually a function, but some MySQL version does not support the specific you try, There is also a date format query processing is also very simple date_format (
T1.cfcadownloadtime,
'%y-%m-%d%h:%i:%s ') write the format you want OK, the date this piece is relatively simple, but this loop batch return ID really is baffled me for a long time, we all know <selectkey resulttype= "Integer" Keyproperty = "UID" order= "after" >
SELECT
LAST_INSERT_ID () as UID
</selectKey> this way can return a single ID, in fact, his way is to query the last one to add data to the primary key, or usegeneratedkeys= "true" keyproperty= "rid" this way, but the bulk of him is not, Search in Baidu for a long time to see a lot of people also encountered this problem in fact the reason is also very simple MyBatis to 3.1 version above OK, this can be said to be mybatis a bug in 3.1 after the repair, although these problems seem simple but do it is really trouble, also is a lesson
MySQL Date function and bulk loop return primary Key ID