473,545 Members | 721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing Time in System.DateTime

I have no problem storing dates + times in a
System.DateTime object. In addition, it's easy to output
a Time as a string from an existing Date/Time. But I'm
having trouble storing a time only. Is there any way to
store only a time without the date portion (like 3:00 am)
in this data structure? Or, if not, is there another
data structure that would be preferable?

Thanks

robert
Jul 21 '05 #1
2 1802
Robert <ch******@pobox .upenn.edu> wrote:
I have no problem storing dates + times in a
System.DateTime object. In addition, it's easy to output
a Time as a string from an existing Date/Time. But I'm
having trouble storing a time only. Is there any way to
store only a time without the date portion (like 3:00 am)
in this data structure? Or, if not, is there another
data structure that would be preferable?


No, it will *always* store the date part as well - but that doesn't
mean that you have to take any notice of it. Just create a new DateTime
which has (say) year 1970, month 1, day 1 and then the right time.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
You can store it into a TimeSpan, as the interval of time that elapsed
between midnight and your time.

This way you can easily reconstruct a full date time from a date (at
midnight) and a time, you can just add the time expressed as TimeSpan to the
date.

I find this representation cleaner than a DateTime at an arbitrary date (Jan
1st 1970, Jan 1st 1900, ...).

Bruno.

"Robert" <ch******@pobox .upenn.edu> a écrit dans le message de
news:06******** *************** *****@phx.gbl.. .
I have no problem storing dates + times in a
System.DateTime object. In addition, it's easy to output
a Time as a string from an existing Date/Time. But I'm
having trouble storing a time only. Is there any way to
store only a time without the date portion (like 3:00 am)
in this data structure? Or, if not, is there another
data structure that would be preferable?

Thanks

robert

Jul 21 '05 #3

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

Similar topics

3
35058
by: Jon Davis | last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST" The problem: // this fails on PST DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST"); Help? Jon
7
7036
by: Drunkalot | last post by:
How can I set the system time using a DateTime object??? s...
2
331
by: Robert | last post by:
I have no problem storing dates + times in a System.DateTime object. In addition, it's easy to output a Time as a string from an existing Date/Time. But I'm having trouble storing a time only. Is there any way to store only a time without the date portion (like 3:00 am) in this data structure? Or, if not, is there another data structure...
7
2668
by: Dick | last post by:
I have a long list of events. I know where each event took place (globally) and when (using the event’s local time). I want to do some comparisons between these date/times. I thought I would convert them all to UTC and thus get them all on a common time-line. But I can’t see how to do this. I can use TimeZone.CurrentTimeZone to get the...
3
5310
by: john | last post by:
I am using MS Sql Express as the backend database for a Microsoft Access front end application. I am using a calendar control to store the desired date in the sql datetime field. The time portion of the field defaults to 12:00am. What I want is to also store the time in the same datetime field as the date, but I want to use a separate...
7
1989
by: JamesG | last post by:
Hi, I need to convert the current time to the format "hh:mm:ss" and date to the format "yyyy-MM-dd". The result of both conversions needs to be of System.DateTime format. I've tried using DateTime.ParseExact and DateTimeFormatInfo but failed, most examples I see convert the final result to a string... I dont want that!
2
1716
by: Bubbs | last post by:
hi, Lemme give u a little background on my problem. Ive created a client and server applications that receive and stream live time values. The client software is a clock that receives the time and displays it in a wpf app. Now when i use the DateTime.Now on the client app locally without using streaming the clock works great. However when I...
4
1843
by: John A Grandy | last post by:
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 ?
25
4521
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this evaluates to true when the time is not greater than dtmTime #9:32:34 PM# Why is that? and How can I get this to work? Brian
0
7465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7805
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5325
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
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 we have to send another system
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.