获取开始周和结束周之间的周数 [英] get the count of week in between start week and end week

查看:97
本文介绍了获取开始周和结束周之间的周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个下拉列表.每一个都包含开始周和结束周的详细信息.

开始周:1-2006(2006年第一周)至52-2020(2020年52周)
结束一周:1-2006至52-2020

如果我选择开始周"1-2006"(2006年的第一周)和结束周""41-2007"(41年,2007年),那么我想获取开始周和结束周之间的周数.

注意:直到2020年,数据库中硬编码的开始周和结束周数据.例如1-2006到52-2020,包括leap年.

我只是想根据开始周和结束周的下拉列表计算周数.

我们该怎么做.

请帮助并给我解决方案.

问候,
Ganesh.S

Hi,

I have two dropdown list. Each one contain start week and End week Details.

Start Week : 1-2006(1st Week,year 2006) to 52-2020 (52 week,2020 Year)
End Week : 1-2006 to 52-2020

if i select startweek "1-2006" (1st week,2006 year) and EndWeek "41-2007" (41st week,2007 Year) then i want to get the count of week in between start week and end week.

Note : start week and end week data Hardcoded in the database till 2020. like 1-2006 to 52-2020 including leap year.

Just i want to count the number of weeks based on start week and end week dropdown.

How we can do that.

pls. help and give me the solution.

Regards,
Ganesh.S

推荐答案

public int returnTotWeeks(string s1,string s2)
{
试试
{
string [] str1 = s1.Split(''-'');
string [] str2 = s2.Split(''-'');
int d1 =(Convert.ToInt32(str2 [1])-Convert.ToInt32(str1 [1]))* 52;
返回d1 +(Convert.ToInt32(str2 [0])-Convert.ToInt32(str1 [0]))+1;
}
catch(特例除外)
{
Response.Write(错误归因于":+ ex.StackTrace);
返回0;
}
}
public int returnTotWeeks(string s1, string s2)
{
try
{
string[] str1 = s1.Split(''-'');
string[] str2 = s2.Split(''-'');
int d1 = (Convert.ToInt32(str2[1]) - Convert.ToInt32(str1[1])) * 52;
return d1 + (Convert.ToInt32(str2[0]) - Convert.ToInt32(str1[0])) + 1;
}
catch ( Exception ex)
{
Response.Write("Error due to :" + ex.StackTrace);
return 0;
}
}


这篇关于获取开始周和结束周之间的周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆