如何计算仅次于星期日的天数 [英] how to calulate number of days subrating sundays alone

查看:81
本文介绍了如何计算仅次于星期日的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工作日"文本框datetimepicker(日历)

Netpayabledays文本框


我选择通过编码完成显示的特定月份时的工作日31 datetimepicker(calendar).

Netpayabledays文本框26(我​​希望通过选择特定月份来减去星期日.剩余天数将显示在netpayabledays文本框中.



为了您的理解,我发送了附件文件

Working days textbox datetimepicker(calendar)

Netpayabledays textbox


Working days 31 datetimepicker(calendar) when i choose particular month that days displayed i done through coding.

Netpayabledays textbox 26( i want subracting sundays from selecting a particular month. remaining days to be displayed in netpayable days textbox.



for your understand i send the attach file

推荐答案

目前尚不清楚您想要什么.
但是,如果我猜对了,您想计算一个月中的工作日(工作日).您可以使用 System.DateTime.DayOfWeek [ http://stackoverflow.com/questions/1820173/calculate-the-number-of-weekdays-between-two-dates-in-c-sharp [ http://stackoverflow.com/questions/4022993/how-to-get-a-list-of-week-days-in-a-month [
It is unclear what you want.
But if I guess correctly, you want to calculate weekdays (workdays) in a month. You can use System.DateTime.DayOfWeek[^] property to see what day of week is a specific date.
Here you have some methods: http://stackoverflow.com/questions/1820173/calculate-the-number-of-weekdays-between-two-dates-in-c-sharp[^], you just have to change them to take only Sunday as weekend, and Saturday as weekday/workday.

Update: here i found the most elegant one: http://stackoverflow.com/questions/4022993/how-to-get-a-list-of-week-days-in-a-month[^]. With a little adaptation:

public static int GetWorkdays(int year, int month)
        {
            return Enumerable.Range(1, DateTime.DaysInMonth(year, month))
                             .Select(day => new DateTime(year, month, day))
                             .Where(dt => dt.DayOfWeek != DayOfWeek.Sunday)
                             .Count();
        }
}


这篇关于如何计算仅次于星期日的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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