Date ONLY data type.

  • Thread starter Thread starter ESPNSTI
  • Start date Start date
E

ESPNSTI

Hi,

I'd like to be able to distinguish between a DateTime variable that is
allowed to hold both date and time and a DateTime variable that is allowed
to only hold a Date.
The reason's for this is that I'd like to store DateTime variables that are
allowed to hold date and time as UTC in the database.
However I'd to store DateTime variables that are only allowed to hold a date
(like a birthdate) not as UTC (since adding a +6h time offset to something
that didn't have a time specified in the first place isn't meaningful).
Unfortunately, I DO have scenarios where I have date and time combinations
where 00:00 is a valid entered time (otherwise I could have used that to
determine if it was a date only).

For example I'd like to be able to do something like this:

public static void AddParameter(ref SqlCommand aCommand, string aName,
DateTime aValue)
{
if (!aValue.ISDATEONLY) //<-- ISDATEONLY isn't a method that exists,
I'm looking for something like that.
// The value needs to be save in the database in UTC
aValue = aValue.ToUniversalTime();
AddParameter(ref aCommand, aName, aValue);
}

Now I figured I'd define a class something like this in order to indicate if
a variable is a date only ( I'm used to have something similar available in
Delphi ) :

public class Date : DateTime
{
}

However, DateTime is sealed. :(

Now I could do something like this:

public class Date
{
DateTime Value;
}

However, I'd like to be able to bind properties defined as Date to UI Date /
Time controls, so I'd like to keep working with DateTime. (Or is there an
easy way to bind something like the Date class above to a UI Date / Time
control?)

Ideas?

Thanks,
Erik
 
Hi,

I think your solution is good, create a class with a member of DateTime
and a bool that indicate if it hold a Date only.

You could also add other members as needed.

You could use then MyDate.TheDateTime to bind to the datetimepick control


cheers,
 
Back
Top