關於datediff的使用方法

2021-10-06 16:42:46 字數 406 閱讀 6471

由於工作需要,資料儲存環境可能不限制在固定的某一種軟體,那麼datediff,就需要變換一下使用方法。比如,需要查詢時間間隔為6天內的資料,故條件語句裡面,可以依據軟體版本,選擇新增如下的語句:

where datediff(day,cast(日期字段 as date),getdate())<= 6

這裡,日期欄位為字元格式儲存,所以需要保證該字元為日期格式,如2020-02-01或者20200201,具體可參考軟體的日期儲存格式表,避免有溢位的錯誤字元,以防報錯。

where date_diff(current_date,cast(日期字段 as datetime))<=6

這裡,current_date為日期字段,當前日期只需要取系統預設的字元(可根據不同的軟體版本靈活變更),mysql中使用的方法需要與前面的sql語言做區分。

HQL與SQL關於DATEDIFF的使用工作備份

1.select o.id from insuranceorder as o where select datediff o.expiredate,o.buydate 1460 and select datediff o.expiredate,o.buydate 1095 2.select v.id...

關於CASE WHEN的 使用方法

case具有兩種格式。簡單case函式和case搜尋函式。簡單case函式 case when 1 then 男 when 2 then 女 else 其他 end case搜尋函式 case when 1 then 男 when 2 then 女 else 其他 end 這兩種方式,可以實現相同的...

關於rem的使用方法

rem font size of the root element 是指相對於根元素的字型大小的單位。簡單的說它就是乙個相對單位。看到rem大家一定會想起em單位,em font size of the element 是指相對于父元素的字型大小的單位。它們之間其實很相似,只不過rem計算的規則是依...