Hi for some reason I cant do a string comparison on a date? Take for example:
public List<HireDate> GetHireDate(string anything)
{
List<HireDate> hiredate = hiredates.Where(n =>
string.Equals(n.HireFromDate, anything, StringComparison.CurrentCultureIgnoreCase)
).ToList();
return hiredate;
}
It simply wont work? if I type into a textbox 13/07/2012 which is how its stored it returns a 404 not found???
The output looks like this from a generic list/get request:
<ArrayOfHireDate>
<HireDate>
<HireFromDate>13/07/2012</HireFromDate>
<HireToDate>28/07/2012</HireToDate>
<NumberOfDaysHired>15</NumberOfDaysHired>
</HireDate>
</ArrayOfHireDate>
Is there another way to find a string with a forward slash in it? For instance using / in any of web string comparers does not work it will always throw a 404 not found?
Two things:
1) To put a string in another string, the most common way to do this is using
String.Format. That method takes a format string (such as"Date: {0} Time: {1}") and a bunch of arguments. Each occurrence of{0}in the string is replaced by the first argument,{1}by the second, etc.. There are additional options to format the arguments in the string, see for more information the MSDN page onString.Format.2) If you have an URL and you get a 404 in your application, first verify that the syntax of the URL is correct. Manually try the URL you create in your program directly in your browser, and if it does not work, find out what syntax is actually used to provide the arguments. For example, it might be that a date must be formatted as
13-07-2012instead of13/07/2012for it to work. If so, you can probably solve this by choosing the appropriateCultureInfo.For any
DateTime dateobject, to format it has a short date using anyCultureInfoyou want, use an overload ofToStringand specifydas the format. For example, using the invariant culture:Other format strings can be found here.