enrique_aeo
asked on
DateTime 01/01/0001
hi experts
this variable model.fec_obs_concal contains the value: 01/01/0001 when not selected date,
the value could be null or empty
public DateTime fec_obs_concal { get; set; }
public DateTime concal_fecha { get; set; }
fecha01010001.png
this variable model.fec_obs_concal contains the value: 01/01/0001 when not selected date,
the value could be null or empty
public DateTime fec_obs_concal { get; set; }
public DateTime concal_fecha { get; set; }
fecha01010001.png
and your question is?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i do
public DateTime? fec_obs_concal { get; set; }
i have this error:
CS0266 C# Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
public DateTime? fec_obs_concal { get; set; }
i have this error:
CS0266 C# Cannot implicitly convert type 'System.DateTime?' to 'System.DateTime'. An explicit conversion exists (are you missing a cast?)
have you tried Shaun comment?
Did you also change the definition of concal_fecha to be a Nullable DateTime?
You will need to look through your code for other places where dates will need to allow nulls and make the needed changes.
You will need to look through your code for other places where dates will need to allow nulls and make the needed changes.
ASKER
thanks
I made the change throughout the project
I made the change throughout the project
Date's cannot be empty. The default value (which equates to the DateTime.Min value) is '01/01/0001 12:00 AM'. Proof of concept -
Just an FYI, trying to parse a null value results in the MinValue being set for the date.
That being said, as the others have stated you can add Null support to the DateTime variable by specifying a Nullable<DateTime> or DateTime?. This will allow for you to support null values for Dates, but remember, that DateTime's cannot be empty.
-saige-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EE_Q28962384
{
class Program
{
static DateTime date1;
static void Main(string[] args)
{
Console.WriteLine("Date1 = {0}", date1);
Console.WriteLine("Default DateTime = {0}", default(DateTime));
Console.WriteLine("DateTime.Min = {0}", DateTime.MinValue);
Console.ReadLine();
}
}
}
Produces the following output -If you try to parse an empty string you end up with -Which means you are left with using a try...catch or DateTime.TryParse. If the parse fails, the output is still the MinValue. Proof of concept:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EE_Q28962384
{
class Program
{
static DateTime date1;
static void Main(string[] args)
{
Console.WriteLine("Date1 = {0}", date1);
Console.WriteLine("Default DateTime = {0}", default(DateTime));
Console.WriteLine("DateTime.Min = {0}", DateTime.MinValue);
if (DateTime.TryParse("", out date1))
Console.WriteLine("Date1 has changed successfully - {0}", date1);
else
Console.WriteLine("Date1 failed to changed, MinValue assigned - {0}", date1);
Console.ReadLine();
}
}
}
Which produces the following output -Just an FYI, trying to parse a null value results in the MinValue being set for the date.
That being said, as the others have stated you can add Null support to the DateTime variable by specifying a Nullable<DateTime> or DateTime?. This will allow for you to support null values for Dates, but remember, that DateTime's cannot be empty.
-saige-