473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Are DateTime datatypes worth the aggravation?

They're driving me nuts, especially with the Datareader.
There are times when I want to pass a null date on
to a date variable and I have to cast the null as a
date!!!???

I'm wondering if I should just forget it and dates and times
as a string in the database table.

Anyone wrestle with this decision?

Oct 28 '06 #1
9 1335

"Tony Van" <to*********@comcast.netwrote in message
news:Vp******************************@comcast.com. ..
They're driving me nuts, especially with the Datareader. There are times
when I want to pass a null date on
to a date variable and I have to cast the null as a date!!!???

I'm wondering if I should just forget it and dates and times as a string
in the database table.

Anyone wrestle with this decision?

I guess it would depend on what sort of processing you need to do with dates
and times. If all you need to do is store a date and time, and you'll never
need to compare two date-times, or do any other manipulation, then I guess
strings are OK. If you ever did need to calculate an interval between two
date-times, or, say, add a value, such as 30 days to a date-time, etc. you
might be sorry you chose strings.
Oct 28 '06 #2
If you store dates as a string, you are more or less breaking the first
normal form, as you are storing the date as several separate values in
the same field. That would give you a hint that it might not be the best
idea.

If you store the dates as strings, you can't really use them for much
anything than displaying them, and even then you can run into problems.
What if you one day need to display the dates in a different format?
Then you would have to convert the strings to dates, then convert them
back to strings in a different format. You will look at the mess, and
wonder what the @&#%¤ you were thinking when you stored the dates as
strings...

If you are using framework 2, you can use a nullable date to handle date
values that may be null.

Tony Van wrote:
They're driving me nuts, especially with the Datareader.
There are times when I want to pass a null date on
to a date variable and I have to cast the null as a
date!!!???

I'm wondering if I should just forget it and dates and times
as a string in the database table.

Anyone wrestle with this decision?
Oct 29 '06 #3
Tony,

As addition to the others, if your program is only build for one culture,
but only one culture than it maybe fit. And with culture I mean culture by
instance the USA culture which fits almost nowhere in the world beside the
USA (even not Canada or Australia). (Microsoft software including dotNet by
instance is MultiCulture)
Cor

"Tony Van" <to*********@comcast.netschreef in bericht
news:Vp******************************@comcast.com. ..
They're driving me nuts, especially with the Datareader. There are times
when I want to pass a null date on
to a date variable and I have to cast the null as a date!!!???

I'm wondering if I should just forget it and dates and times as a string
in the database table.

Anyone wrestle with this decision?

Oct 29 '06 #4
I'll take a slightly different tack from the other replies. I'll say
"probably" you want to use the datetime but be willing to consider
alternatives if you have special needs.

I'm looking at the SQL Server docs right now and it plainly says:I'm looking
at the SQL Server docs right now and it plainly says: "Date and time data
from January 1, 1753, through December 31, 9999, with an accuracy of 3.33
milliseconds "

It seems clear that if your dates fall outside of that range (earlier only I
would imagine) you'll encounter problems. Similarly if you need more than
just "null" (there is such a concept as multiple null values (they are all
null but for different reasons)) you can't represent them. The alternative
(and a bad one) is to choose particular dates (maybe the highest few) to
represent these special values.

Hope this helps,
Tom

"Tony Van" <to*********@comcast.netwrote in message
news:Vp******************************@comcast.com. ..
They're driving me nuts, especially with the Datareader. There are times
when I want to pass a null date on
to a date variable and I have to cast the null as a date!!!???

I'm wondering if I should just forget it and dates and times as a string
in the database table.

Anyone wrestle with this decision?

Oct 29 '06 #5
All true, but a null date in some areas of my DB are
meaningful. I suppose I can make the MinDate serve as a
flag for an empty date. But you know, I'm already casting
all over the place in my code so a cast from string to
datetime seem trivial.

Thanks for the input. as I continue to mull this over.
Oct 29 '06 #6
Hi Tony,

Casting a string to datetime may be trivial, but running queries on string
dates is not. If you want to be able to work with your datetime data in the
database itself (filter conditions, sorting, for example), use the datetime
data type.

Think about it. You've already acquainted yourself with the DateTime data
type, and most of the issues that surround it when working with ADO.Net and
Controls. There are some very good reasons for the DateTime data type, some
of which you may not even be aware of (such as TimeZone issues). Let me
point you to some excellent resources to help you get over the hump, and
then you can decide for yourself what to do:

http://msdn2.microsoft.com/en-us/library/ms172138.aspx
http://support.microsoft.com/kb/313513
http://msdn2.microsoft.com/en-us/library/ms228044.aspx
http://www.codeproject.com/cs/miscct...TimePicker.asp
http://www.codeguru.com/csharp/cshar...e.php/c9645__1
http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx
http://msdn2.microsoft.com/en-us/library/2cf62fcy.aspx
http://msdn2.microsoft.com/en-us/lib....nullable.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Short Order Coder
http://unclechutney.blogspot.com

The devil is in the yada yada yada
"Tony Van" <to*********@comcast.netwrote in message
news:mI******************************@comcast.com. ..
All true, but a null date in some areas of my DB are meaningful. I
suppose I can make the MinDate serve as a flag for an empty date. But
you know, I'm already casting all over the place in my code so a cast
from string to datetime seem trivial.

Thanks for the input. as I continue to mull this over.

Oct 29 '06 #7
To be clear I'm not suggesting that you should or shouldn't use the datetime
datatype.

Re: null values, I was also pointing out that one "null" is often not
enough. A null value is generally interpreted as "never been entered" when
in fact that is only one possibility. It may be unknown or unavailable
which may be considered "we entered a null" rather than "it has a null
because we never entered it". There can be "doesn't apply" type nulls as
well as others. These are fairly easy to represent as coded values but with
datetime you have to choose a real datetime to represent each null subtype.

BTW MinDate is a date that could reasonably represent real data. Given the
range of datetime you can't even store Columbus's voyage to America as a
datetime type. Nothing we tend to store consists of MaxDate values however
and I know of no database that has 12/31/9999 as a date which represents
anything real.

I'll also suggest that everybody casts all over the place in order to
display things properly . An item stored as Boolean doesn't imply we want F
or T as the representation of the value. These are often shown as
True/False, Yes/No or what have you and as such are cast to strings. So I
agree it isn't an issue. Basically see if datetime meets your requirements
much like you check if any other data type meets your requirements. Am I
mistaken in believing that if people need to store dates for the first 17
centuries AD they aren't doing it using datetime?

Keep mulling :-)
"Tony Van" <to*********@comcast.netwrote in message
news:mI******************************@comcast.com. ..
All true, but a null date in some areas of my DB are meaningful. I
suppose I can make the MinDate serve as a flag for an empty date. But
you know, I'm already casting all over the place in my code so a cast
from string to datetime seem trivial.

Thanks for the input. as I continue to mull this over.

Oct 29 '06 #8
Tom,

Be aware that Columbus voyage to America took place before 1582 the year
most modern western countries from that time started with the Georgian
Calendar. The British Empire (including current USA) started with that in
September 1752 therefore dates during that and before that period are very
insecure measured to our current standards.

Although I am probably one of the most datetime puritans in these newsgroup:
I use string dates in our kind of genealogic families website in a XML file
(dataset). The reason is the one you mentioned and because that I than don't
have to change in the browser. I have the information in a database where I
add 2000 to all dates before 1800 and there it are true datetime variables.

Cor
"Tom Leylan" <ge*@iamtiredofspam.comschreef in bericht
news:%2******************@TK2MSFTNGP05.phx.gbl...
To be clear I'm not suggesting that you should or shouldn't use the
datetime datatype.

Re: null values, I was also pointing out that one "null" is often not
enough. A null value is generally interpreted as "never been entered"
when in fact that is only one possibility. It may be unknown or
unavailable which may be considered "we entered a null" rather than "it
has a null because we never entered it". There can be "doesn't apply"
type nulls as well as others. These are fairly easy to represent as coded
values but with datetime you have to choose a real datetime to represent
each null subtype.

BTW MinDate is a date that could reasonably represent real data. Given
the range of datetime you can't even store Columbus's voyage to America as
a datetime type. Nothing we tend to store consists of MaxDate values
however and I know of no database that has 12/31/9999 as a date which
represents anything real.

I'll also suggest that everybody casts all over the place in order to
display things properly . An item stored as Boolean doesn't imply we want
F or T as the representation of the value. These are often shown as
True/False, Yes/No or what have you and as such are cast to strings. So I
agree it isn't an issue. Basically see if datetime meets your
requirements much like you check if any other data type meets your
requirements. Am I mistaken in believing that if people need to store
dates for the first 17 centuries AD they aren't doing it using datetime?

Keep mulling :-)
"Tony Van" <to*********@comcast.netwrote in message
news:mI******************************@comcast.com. ..
>All true, but a null date in some areas of my DB are meaningful. I
suppose I can make the MinDate serve as a flag for an empty date. But
you know, I'm already casting all over the place in my code so a cast
from string to datetime seem trivial.

Thanks for the input. as I continue to mull this over.


Oct 30 '06 #9
Hey Cor that's good information. As you point out however at times we're
still stuck having to represent dates outside of the range provided.
Offsetting the dates certainly works. I think Tony has more to think about
now :-)
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:u6****************@TK2MSFTNGP03.phx.gbl...
Tom,

Be aware that Columbus voyage to America took place before 1582 the year
most modern western countries from that time started with the Georgian
Calendar. The British Empire (including current USA) started with that in
September 1752 therefore dates during that and before that period are very
insecure measured to our current standards.

Although I am probably one of the most datetime puritans in these
newsgroup: I use string dates in our kind of genealogic families website
in a XML file (dataset). The reason is the one you mentioned and because
that I than don't have to change in the browser. I have the information in
a database where I add 2000 to all dates before 1800 and there it are true
datetime variables.

Cor
"Tom Leylan" <ge*@iamtiredofspam.comschreef in bericht
news:%2******************@TK2MSFTNGP05.phx.gbl...
>To be clear I'm not suggesting that you should or shouldn't use the
datetime datatype.

Re: null values, I was also pointing out that one "null" is often not
enough. A null value is generally interpreted as "never been entered"
when in fact that is only one possibility. It may be unknown or
unavailable which may be considered "we entered a null" rather than "it
has a null because we never entered it". There can be "doesn't apply"
type nulls as well as others. These are fairly easy to represent as
coded values but with datetime you have to choose a real datetime to
represent each null subtype.

BTW MinDate is a date that could reasonably represent real data. Given
the range of datetime you can't even store Columbus's voyage to America
as a datetime type. Nothing we tend to store consists of MaxDate values
however and I know of no database that has 12/31/9999 as a date which
represents anything real.

I'll also suggest that everybody casts all over the place in order to
display things properly . An item stored as Boolean doesn't imply we
want F or T as the representation of the value. These are often shown as
True/False, Yes/No or what have you and as such are cast to strings. So
I agree it isn't an issue. Basically see if datetime meets your
requirements much like you check if any other data type meets your
requirements. Am I mistaken in believing that if people need to store
dates for the first 17 centuries AD they aren't doing it using datetime?

Keep mulling :-)
"Tony Van" <to*********@comcast.netwrote in message
news:mI******************************@comcast.com ...
>>All true, but a null date in some areas of my DB are meaningful. I
suppose I can make the MinDate serve as a flag for an empty date. But
you know, I'm already casting all over the place in my code so a cast
from string to datetime seem trivial.

Thanks for the input. as I continue to mull this over.



Oct 30 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
6102
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
0
1223
by: Kevin | last post by:
Greetings. I am using a myDataSet.WriteXml(StringWriter) function (and then using the ToString() function to convert it to a string) to build an XML string based on the contents of my dataset. ...
1
1906
by: Marc | last post by:
I need to read and filter data from a data table on a remote sql server. The data needs to be filtered by a column DateTimeIn. I need to filter a week's worth of information depending on what a...
2
7969
by: jason | last post by:
hello all, silly question, but i can't find a thread that answers it. i have stored procedures that have output parameters of the datatypes Money and DateTime. i have the following sample...
2
2476
by: John A Grandy | last post by:
VS05 : GridView control config'd to use SPs in SS05 One of the SPs takes a vchar(50) which in the T-SQL needs to be converted to a DateTime. How should I have the GridView format the text the...
4
2738
by: jsnX | last post by:
I'm having trouble determining whether or not the period in an xsd:dateTime like this: 2006-10-04T03:42:12.3Z should in fact be a comma, as date(1) would have it: date --utc --iso-8601=ns...
29
2739
by: dyork | last post by:
When getting data from a database using the dbapi and an SQL query, how do you in general round trip the data? Especially date-time? An SQL datetime column translates nicely into a Python...
5
2842
by: shapper | last post by:
Hello, I defined a DateTime variable: Dim dt As New DateTime How can I check if it is empty? Basically I want to check if it was given to it a DateTime value or not.
0
758
by: Andres Bohren | last post by:
Hi i have a GridView and have Problems to put the values into the right Datatypes. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.