kwh3856
asked on
Cannot implicitly convert type 'string' to 'System.DateTime'
I am trying to initialize a data variable. I initializing the variable to 0's but when I saved it to the database the database gave an error message of
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Now, I am trying to set the variable to this date and time for the initilization. When I try to set the variable it gives me the Cannot Implicitly convert type 'string' to SystemDateTime.
Can someone show me the correct syntax to accomplish this task?
Here is my code:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
Now, I am trying to set the variable to this date and time for the initilization. When I try to set the variable it gives me the Cannot Implicitly convert type 'string' to SystemDateTime.
Can someone show me the correct syntax to accomplish this task?
Here is my code:
DateTime dt = new DateTime();
if (dt.CompareTo(new DateTime()) == 0)
{
// Date is set to min, 1/1/0001 12:00:00 AM
// SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
dt = "1/1/1753 12:00:00 AM";
}
else
{
MyGlobalVars.dob = Convert.ToDateTime(userrec.patuser.dob);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A string has to be explicitly converted to datetime... Using either DateTime.Parse or Convert.ToDateTime
hi,
using datetime as string literal can be done with # symbol as prefix and postfix
dt = "#1/1/1753 12:00:00 AM#";
-thanks
using datetime as string literal can be done with # symbol as prefix and postfix
dt = "#1/1/1753 12:00:00 AM#";
-thanks
ASKER
That worked PERFECT!!!!
Thanks
Kenny
Thanks
Kenny