开发者

to display only weekdays weekdays

I have a input date picker which will pick the current system date. onclick of button. I need to add nine bussiness days to current day and display it into input value, so that only weekdays are exclude when we add the days.

For example, if you have today's date (01/31/2011) a开发者_Python百科nd i want to add 9 days, the answer should be 10/3/06 because the(02/03/2011) weekend should not be counted.

Does anyone know how this can be done?


for this you need to crate one sql function like:

create function fn_IsWeekDay ( @date datetime ) returns bit as begin

declare @dtfirst int
declare @dtweek int 
declare @iswkday bit 

set @dtfirst = @@datefirst - 1
set @dtweek = datepart(weekday, @date) - 1

if (@dtfirst + @dtweek) % 7 not in (5, 6)
    set @iswkday = 1 --business day
else
    set @iswkday = 0 --weekend

return @iswkday

end

Short and sweet. Now you can simply do this:

if dbo.fn_IsWeekDay(@date) = 1 begin --do some magic here ; end

--or

implemented functionality


You probably will need something more advanced, but assuming that you just want to discard Saturday and Sunday you can do something like this (just basic calculation, hope I did not count wrong):

<script>
today = new Date();
endDate=today; //Init.

alert(today);

dayOfWeek=today.getDay();

//0: Sunday
if(dayOfWeek==0 || dayOfWeek==1)endDate.setDate(today.getDate() + 11);
else if(dayOfWeek==6)endDate.setDate(today.getDate() + 12);
else endDate.setDate(today.getDate() + 13);

alert(endDate);
</script>

EDIT: this assumes "woking days" Mon, Tue, Wed, Thu, Fri

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜