brendanlefavre
asked on
C# Syntax help - Set bool if date is greater than 12 months
I'm trying to set employee.HireDateAdjusted to true if the date from employee.HireDate is greater that 12 months. I think I am close, but i cannot seem to get the boolean syntax right
if (dt.Rows.Count > 0)
{
employee.HireDate = Convert.ToDateTime(dt.Rows[0]["HireDate"]).ToShortDateString();
if (employee.HireDate > DateTime.Today.AddMonths(12).ToString())
{
employee.HireDateAdjusted = true;
}
else
{
employee.HireDateAdjusted = false;
}
}
Remove the ToString call in line 4.
Also, a shortcut:
employee.HireDateAdjusted = (employee.HireDate > DateTime.Today.AddMonths(12));
ASKER
I'm getting a notification that operator '>' cannot be applied to operands of type string and type System.Date.Time
are you trying to find out if the employee was hired more than 12 months ago?
if so then
if (employee.HireDate.Addmont hs(-12) >= DateTime.Today)
{
// Hired more than 12 months ago
employee.HireDateAdjusted = true;
}
else
{
// hired less than 12 months ago
employee.HireDateAdjusted = false;
}
}
if so then
if (employee.HireDate.Addmont
{
// Hired more than 12 months ago
employee.HireDateAdjusted = true;
}
else
{
// hired less than 12 months ago
employee.HireDateAdjusted = false;
}
}
Have you removed the ToString call as I demonstrated above?
ASKER
yes, the ToString was removed
The HireDate is of type string, and it's value is coming from a WCF service that is retreiving it's values from a query to an Oracle Linked server.
[DataMember]
public string HireDate;
if i change the HireDate type to DateTime, the above methods will compile properly, but the values from the linked server get set to 1/1/1900
The HireDate is of type string, and it's value is coming from a WCF service that is retreiving it's values from a query to an Oracle Linked server.
[DataMember]
public string HireDate;
if i change the HireDate type to DateTime, the above methods will compile properly, but the values from the linked server get set to 1/1/1900
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
worked perfectly!
thanks for the help,
Jason
thanks for the help,
Jason