With this code:
public static bool PlatypusIsAFornightOrLessOld(int PlatypusID) {
const int FORTNIGHT = 14;
const string sql = @"SELECT PLATYPUSBIRTHDATE
FROM PLATYPI
WHERE PLATYPUSID = :PLATYPUSID";
DateTime dt;
try {
using (var ocmd = new OracleCommand(sql, oc)) {
ocmd.Parameters.Add("PLATYPUSID", PlatypusID);
dt = Convert.ToDateTime(ocmd.ExecuteScalar());
}
return (DateTime.Today - dt) <= FORTNIGHT;
} catch (Exception e) {
. . .
I’m getting: “Operator ‘<=’ cannot be applied to operands of type ‘System.TimeSpan’ and ‘int'” on the “return” line.
Others have suggested going from the
TimeSpanto the number of days. I would suggest it’s cleaner to representFORTNIGHTas aTimeSpantoo. Alternatively, even better yet: work out the deadline as aDateTimeand avoid the subtraction entirely:Also, I hope that you haven’t really got
catch(Exception e)in your real code. You should almost never catchException– and definitely not in the same method which is doing SQL operations.