468,505 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Date ONLY data type.

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
Nov 17 '05 #1
1 9338
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ESPNSTI" <ES*********@Hotmail.com> wrote in message
news:eE**************@TK2MSFTNGP09.phx.gbl...
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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Yong Wang | last post: by
1 post views Thread by John Cosmas | last post: by
1 post views Thread by Alan | last post: by
1 post views Thread by glenn | last post: by
3 posts views Thread by glenn | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.