[英]If there are four weeks,how to store the data of single week in the database by selecting the week?
I want to store the dates for particular week in the database. 我想将特定星期的日期存储在数据库中。 EG: If 1-3-2015 to 7-3-2015 is week 1,then I want to store 8-3-2015 to 14-3-2015 as week 2 and etc. How can I store this as weeks in database.
EG:如果1-3-2015至7-3-2015是第1周,那么我想将8-3-2015至14-3-2015作为第2周存储,依此类推。如何将其作为周存储在数据库中。
Create a Table : 创建一个表:
`TableName WeekInfo' TableName WeekInfo
WeekId int
StartDate DateTime
EndDate DateTime
and then use the WeeKInfo Table's WeekId
in your actual table. 然后在实际表格中使用WeeKInfo表的
WeekId
。
try this. 尝试这个。
declare @date datetime = getdate()
declare @wkid int
set @wkid=(select datepart(day, datediff(day, 0, @date)/7 * 7)/7 + 1)
insert into table_name (ekid,date1) values(@wkid,@date)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.