473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 1785
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.com>
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
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
by: Drunkalot | last post by:
How can I set the system time using a DateTime object??? s...
2
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. ...
7
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...
3
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...
7
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...
2
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...
4
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...
25
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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...

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.