Last post Oct 11, 2017 07:11 AM by erum
Member
84 Points
1323 Posts
Oct 11, 2017 06:32 AM|erum|LINK
hello to every one
I have following function in class
public static DateTime AddBusinessDays(DateTime dt, int nDays) { int weeks = nDays / 5; nDays %= 5; while (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday) dt = dt.AddDays(1); while (nDays-- > 0) { dt = dt.AddDays(1); if (dt.DayOfWeek == DayOfWeek.Saturday) dt = dt.AddDays(2); } return dt.AddDays(weeks * 7); }
and i calling it by below usage
lblReturnDate.Text = Utilities.Utilities.AddBusinessDays(DateTime.Now,15);
but it gives error message
Error 1 Cannot implicitly convert type 'System.DateTime' to 'string'
All-Star
48340 Points
18014 Posts
Oct 11, 2017 06:45 AM|PatriceSc|LINK
Hi,
You need to explicitly convert the computed datetime to a string. For example :
lblReturnDate.Text = Utilities.Utilities.AddBusinessDays(DateTime.Now,15).ToString("d");
d is the short date pattern for the culture under which your site runs. See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings for details.
Oct 11, 2017 07:11 AM|erum|LINK
ok thanks ,solved
Member
84 Points
1323 Posts
error in datetime calling function
Oct 11, 2017 06:32 AM|erum|LINK
hello to every one
I have following function in class
and i calling it by below usage
but it gives error message
Error 1 Cannot implicitly convert type 'System.DateTime' to 'string'
All-Star
48340 Points
18014 Posts
Re: error in datetime calling function
Oct 11, 2017 06:45 AM|PatriceSc|LINK
Hi,
You need to explicitly convert the computed datetime to a string. For example :
lblReturnDate.Text = Utilities.Utilities.AddBusinessDays(DateTime.Now,15).ToString("d");
d is the short date pattern for the culture under which your site runs. See https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings for details.
Member
84 Points
1323 Posts
Re: error in datetime calling function
Oct 11, 2017 07:11 AM|erum|LINK
ok thanks ,solved