本文介紹了如何使用 dateadd 獲取去年的第一天?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試提取介于 2014 年 1 月 1 日和去年今天(即 2014 年 8 月 3 日)之間的數據.我將如何使用dateadd"來獲取日期 1/1/14?我正在使用以下代碼來獲取日期 8/3/14.
I'm trying to pull data that falls in between January 1st, 2014 and today's date last year (ie. August 3rd, 2014). How would I go about using ``dateadd` to get the date 1/1/14? I'm using the following code to get the date 8/3/14.
dateadd(yy, -1, getdate())
我想避免顯式搜索 1/1/14,因為在一年的時間里,我希望 sql 查詢找到 1/1/15,而不必返回并重寫它.
I want to avoid explicitly searching for 1/1/14 because in a year's time I'd like the sql query to find 1/1/15 without me having to go back in and rewrite it.
推薦答案
DATEADD(yy, DATEDIFF(yy,0,getdate())-1, 0)
這篇關于如何使用 dateadd 獲取去年的第一天?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!