DATETIME to only return DATE

  • Thread starter Thread starter Dave
  • Start date Start date
* Dave said:
What magic to I need to do to get the DATETIME.Today to only return
the DATE?!?

DateTime.Today contains no time, all time fields are set to zero. Are
you talking about converting it to a String?
 
* Peter Duniho said:
Felix said:
DateTime.Today contains no time, all time fields are set to zero. [...]

Saying DateTime.Today contains no time is like saying an int variable
holding the value 0 contains no integer.

No it isn't. Of course you CAN interpret the time fields of
DateTime.Today as midnight, but looking at the MSDN, it says the fields
are "set to zero". So they are just meaningless, in terms of semantics.
 
Ok....let me rephrase the question. How do I get the DateTime.Today
to return only the Date ie 8/9/2010? No zeros...no 12:00am
representation...JUST the date.

Thanks






* Peter Duniho said:
Felix said:
DateTime.Today contains no time, all time fields are set to zero. [...]
Saying DateTime.Today contains no time is like saying an int variable
holding the value 0 contains no integer.

No it isn't. Of course you CAN interpret the time fields of
DateTime.Today as midnight, but looking at the MSDN, it says the fields
are "set to zero". So they are just meaningless, in terms of semantics.

--
 Felix Palmen       (Zirias)  + [PGP] Felix Palmen <[email protected]>
 web:  http://palmen-it.de/ |            http://palmen-it.de/pub.txt
 my open source projects:     |   Fingerprint: ED9B 62D0 BE39 32F9 2488
 http://palmen-it.de/?pg=pro +                5D0C 8177 9D80 5ECF F683
 
* Dave said:
Ok....let me rephrase the question. How do I get the DateTime.Today
to return only the Date ie 8/9/2010? No zeros...no 12:00am
representation...JUST the date.

Again, are you talking about string conversions? If so, search the msdn
for date format strings. If not, the question isn't meaningful, because
the class DateTime HAS time fields.
 
What isn't useful Felix is a reply telling an individual to go
search. You could give an example of what you're refering to. That
would be helpful to someone that isn't sure what they're looking for.





* Dave said:
Ok....let me rephrase the question.  How do I get the DateTime.Today
to return only the Date ie 8/9/2010?  No zeros...no 12:00am
representation...JUST the date.

Again, are you talking about string conversions? If so, search the msdn
for date format strings. If not, the question isn't meaningful, because
the class DateTime HAS time fields.

--
 Felix Palmen       (Zirias)  + [PGP] Felix Palmen <[email protected]>
 web:  http://palmen-it.de/ |            http://palmen-it.de/pub.txt
 my open source projects:     |   Fingerprint: ED9B 62D0 BE39 32F9 2488
 http://palmen-it.de/?pg=pro +                5D0C 8177 9D80 5ECF F683
 
Felix said:
* Peter Duniho said:
Felix said:
DateTime.Today contains no time, all time fields are set to zero. [...]
Saying DateTime.Today contains no time is like saying an int variable
holding the value 0 contains no integer.

No it isn't. Of course you CAN interpret the time fields of
DateTime.Today as midnight, but looking at the MSDN, it says the fields
are "set to zero". So they are just meaningless, in terms of semantics.

The System.DateTime semantics of 0 hours, 0 minutes, and 0 seconds is
midnight, whether they are set that way by you in your code or by the
Today property.
 
Dave expressed precisely :
Ok....let me rephrase the question. How do I get the DateTime.Today
to return only the Date ie 8/9/2010? No zeros...no 12:00am
representation...JUST the date.

You can't. The object, System.DateTime always has time fields, and
that is what is returned. If you don't need them, they can generally
be ignored. If this is a display thing, then it's a matter of callign
one of the ToXXXDateString functions or using your own custom date
format that leaves off the time...

Conole.WriteLine (today.ToString ("MM/dd/yyyy"));

What specifically are you trying to accomplish - I think others maybe
more helpful if we new what use you were trying to put this timeless
datetime.
 
* Harlan Messinger said:
The System.DateTime semantics of 0 hours, 0 minutes, and 0 seconds is
midnight, whether they are set that way by you in your code or by the
Today property.

Depends wheter you're interested in the general sematics of the class or
in those of this static property. The property's semantics are limited
to the date fields (it says it returns the current day), so an
equally valid implementation would be
| get { return DateTime.Now; }
Of course, this would be a stupid implementation, but it wouldn't
violate the semantics of "Today".

Regards, Felix
 
* Dave said:
What isn't useful Felix is a reply telling an individual to go
search. You could give an example of what you're refering to. That
would be helpful to someone that isn't sure what they're looking for.

I told you what exactly to search for (and you still didn't state if
converting the date to a string /really/ is what you are trying to
achieve). BTW, top-posting really isn't useful at all.
 
Depends wheter you're interested in the general sematics of the class or
in those of this static property. The property's semantics are limited
to the date fields (it says it returns the current day), so an
equally valid implementation would be
| get { return DateTime.Now; }
Of course, this would be a stupid implementation, but it wouldn't
violate the semantics of "Today".

Specifically, the Today property returns a DateTime object with the time
ALWAYS SET TO THE SAME VALUE. The real benefit of the Today property is to
provide an easy way to compare two DateTimes without regard to the time. If
you just want to output a string, there's no difference between using
DateTime.Today and DateTime.Now; you would just construct your format string
to display only the date portion. So with that in mind, it doesn't really
matter what time Today returns as long as it's consistent. In this case the
time happens to be midnight. It's not that Today contains NO time, it's that
the time it contains is IRRELEVANT.
 
The real benefit of the Today property is to provide an easy way to
compare two DateTimes without regard to the time.

Ignore this part; I meant to say that Today simply returns a DateTime
instance that can be used to compare again another DateTime instance without
regard to time. I was making a mental leap between the static Today property
and the Date instance property and it made my statement confusing.
 
* Peter Duniho said:
Felix said:
[...]
No it isn't. Of course you CAN interpret the time fields of
DateTime.Today as midnight, but looking at the MSDN, it says the fields
are "set to zero". So they are just meaningless, in terms of semantics.

You have just said (basically) "an int variable holding the value 0
contains no integer".

No, that's not what I said but what you obviously read. There's a
difference between the technical view on plain data and the meaningful
interpretation of that data. A group of three integers is not
necessarily a time, but given the corresponding semantics, it is.

"Today" does not carry any meaning for the time, it just identifies a
day. A Property called "Today" could return an object with time values
set to anything without violating its semantics, because it just does
not contain a time. As others pointed out, it sets the values that
normally represent a time to zero, so it's easy to do some computations
with the returned object without caring about these values.

The OP's problem however seems to go down to a misconception of what
DateTime.Today really returns, maybe he assumed it actually is a String.

Regards, Felix
 
* Peter Duniho said:
Felix said:
* Peter Duniho said:
Felix Palmen wrote:
[...]
No it isn't. Of course you CAN interpret the time fields of
DateTime.Today as midnight, but looking at the MSDN, it says the fields
are "set to zero". So they are just meaningless, in terms of semantics.

You have just said (basically) "an int variable holding the value 0
contains no integer".

No, that's not what I said but what you obviously read.

You are missing my point. That point is: your statement is logically
equivalent to the same statement made about an int variable, and is just
as incorrect.

You obviously lack some abstraction capabilities. Maybe you get the
point by thinking in concrete usage terms. Take a program that reads
DateTime.Today and later does something with that value where the
result's time is relevant for the program logic: That would be a
semantic error and probably lead to bugs.

If you don't get it now, I really don't care.
 
* Peter Duniho said:
You should care.

I'm not your CS teacher.
DateTime dt1 = DateTime.Now, dt2 = DateTime.Today;
TimeSpan ts = dt1 - dt2;

That's misusing knowledge about implementation details. Exactly what I
was talking about. Well, just go on, write that kind of code.
 
Back
Top