storing pure dates and pure times

  • Thread starter Thread starter John A Grandy
  • Start date Start date
J

John A Grandy

What are some best practices for storing pure dates and pure times in .NET ?

I notice that DateTime.TimeOfDay() returns type TimeSpan , which is
certainly sufficient for storing pure times , but not constrained ...

Do people write their own classes ? Or have I overlooked one or more
intrinsic .NET classes ?
 
Hi John,

i mostly strore culture specific dates and times with
my applications, mostly as a string, created from
DateTime.Now.ToString() which is bound to a
specific culture. Thats what is mostly handy for me,
but you should have a look at this link:

[.NET Development (General) Technical Articles
Coding Best Practices Using DateTime in the .NET Framework]

http://msdn.microsoft.com/en-us/library/ms973825.aspx



Regards

Kerem

--
 
What are some best practices for storing pure dates and pure times in .NET ?

I notice that DateTime.TimeOfDay() returns type TimeSpan , which is
certainly sufficient for storing pure times , but not constrained ...

Do people write their own classes ? Or have I overlooked one or more
intrinsic .NET classes ?

I assume by "pure date" you mean "date without a time". I'd probably
use DateTime or create my own structure which could be converted
to/from DateTime.
 
What are some best practices for storing pure dates and pure times in .NET ?

I notice that DateTime.TimeOfDay() returns type TimeSpan , which is
certainly sufficient for storing pure times , but not constrained ...

Do people write their own classes ?  Or have I overlooked one or more
intrinsic .NET classes ?

What is wrong with the DateTime from the framework?
If you want to just use Dates , you can simply ignore the Time
component.
Not only that but can strip any DateTime of the time component by
using DateTime.Date

I do not know of any "pure time" struct. You can use a DateTime with a
fixed Date component. then you only have a Time delta.
 
What's wrong with it ? Well, perhaps this is a glib answer, but SQL Server
2008 will have separate datatypes for pure time , pure date , and date-time,
and it would be nice to have some congruency in C# ...

But more fundamentally, I think it's asking for trouble to allow a datatype
to contain irrelevant and/or impossible values for the underlying entity
being modeled ...


message
What are some best practices for storing pure dates and pure times in .NET
?

I notice that DateTime.TimeOfDay() returns type TimeSpan , which is
certainly sufficient for storing pure times , but not constrained ...

Do people write their own classes ? Or have I overlooked one or more
intrinsic .NET classes ?

What is wrong with the DateTime from the framework?
If you want to just use Dates , you can simply ignore the Time
component.
Not only that but can strip any DateTime of the time component by
using DateTime.Date

I do not know of any "pure time" struct. You can use a DateTime with a
fixed Date component. then you only have a Time delta.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top