Click here to Skip to main content
15,888,255 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm getting an error saying System.datetime? can't be converted to System.datetime, but an explicit conversion exists. I did a Google search and found a proposed solution... but I still get the error. OPT_EXP is a nullable column. Please take a look and show me what's wrong?

What I have tried:

C#
       public class MC_VARIABLES
       {
           public DateTime? OPT_EXP;
           public DateTime? mOPT_EXP
           {
               get { return mOPT_EXP; }
               set { mOPT_EXP = value; }
           }
       }

public void DTE()
   {
       decimal DTE;

       foreach (KeyValuePair<int,> KVP in dctMC)
       {
           if (KVP.Value.OPT_EXP.HasValue)
           {
               DateTime TDY = DateTime.Now;
               DateTime EXP = KVP.Value.OPT_EXP;           //cannot implicitly convert system.datetime? to system.datetime....not sure how to fix this
               TimeSpan DaysToExp = TDY - EXP;
               DTE = (decimal)(DaysToExp.TotalDays) / 365;
           }
       }
   }
Posted
Updated 15-Mar-16 15:01pm
v3

1 solution

Use:
C#
DateTime EXP = KVP.Value.OPT_EXP.Value;
 
Share this answer
 
Comments
Trader999 15-Mar-16 21:25pm    
Thanks Matt, really appreciate the help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900