SQL:
--本月最後一天
SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
--前二個月的資料 ex:now為九月 則取出七月與八月的資料
SELECT * FROM tableName
WHERE Date between DATEADD(month, -2, GetDate()) and DATEADD(month, 0, GetDate())
Linq:
--指定區間內資料
var invoiceData = (from item in table
where item.Date >= startDT && item.Date <= endDT
select new
{
Id = item.Id,
Date = item.Date
});
參考資訊:
http://topic.csdn.net/t/20040920/18/3391864.html
http://topic.csdn.net/u/20110622/10/11c96822-edf8-4f7b-8cf5-49a8354f6edc.html
http://www.itpub.net/thread-232401-1-1.html
http://blog.sina.com.cn/s/blog_5067ef490100lg49.html
http://horacerobot.blogspot.tw/2010/10/linq-datetime-between.html