.net - VB to C# conversion DateAndTime equivalent -
i'm trying convert vb block c#.
public function addworkingdays(byval datein datetime, _ byval shiftdate integer) datetime dim b integer dim datdate datetime = datein ' adds [shiftdate] number of working days datein' b = 1 shiftdate datdate = datdate.adddays(1) ' loop around until need non-weekend day' if weekday(datdate) = 7 datdate = datdate.adddays(2) end if next return datdate end function
so far i've got
public datetime addworkingdays(datetime datein, int shiftdate) { int b = 0; datetime datdate = datein; // adds [shiftdate] number of working days datein (b = 1; b <= shiftdate; b++) { datdate = datdate.adddays(1); // loop around until need non-weekend day if (dateandtime.weekday(datdate) == 7) { datdate = datdate.adddays(2); } } return datdate; }
i know there doesn't exist in c# dateandtime put in if statement complete block of code. real problem getting if statement work. not sure if datetime.now.weekday same statement in previous vb code.
weekday
returns 7
saturday
, can use datetime.dayofweek
property , compare dayofweek.saturday
:
if (datdate.dayofweek == dayofweek.saturday) { datdate = datdate.adddays(2); }
Comments
Post a Comment