469,613 Members | 1,927 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Ways to set Second to zero in a DateTime?

Jen
So I have the need to take UtcNow and change the Second to zero. Just
wondering how many ways there are to do that?
Mar 29 '07 #1
2 13193
On Wed, 28 Mar 2007 16:57:38 -0700, Jen <no**@nowhere.comwrote:
So I have the need to take UtcNow and change the Second to zero. Just
wondering how many ways there are to do that?
I would not be so bold as to put an upper bound on the number of ways to
do what you ask.

However, a couple of simple ways you might want to consider include:

* Use the DateTime.AddSeconds() method to add the negative of the
seconds property to the instance, which will set the seconds to zero

* Use one of the many constructors that exist for the DateTime
structure that include the seconds, copying all of the fields from an
initialized copy of DateTime.UtcNow except for the seconds field, which
you'll set to 0.

I don't doubt that there are many other alternatives, most of which are
probably a lot more complicated than the above. :)

Pete
Mar 29 '07 #2
Jen
Thanks, I did the New DateTime method. Kind of verbose but still only one
line of code.
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Wed, 28 Mar 2007 16:57:38 -0700, Jen <no**@nowhere.comwrote:
>So I have the need to take UtcNow and change the Second to zero. Just
wondering how many ways there are to do that?

I would not be so bold as to put an upper bound on the number of ways to
do what you ask.

However, a couple of simple ways you might want to consider include:

* Use the DateTime.AddSeconds() method to add the negative of the
seconds property to the instance, which will set the seconds to zero

* Use one of the many constructors that exist for the DateTime
structure that include the seconds, copying all of the fields from an
initialized copy of DateTime.UtcNow except for the seconds field, which
you'll set to 0.

I don't doubt that there are many other alternatives, most of which are
probably a lot more complicated than the above. :)

Pete

Mar 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Manish Jain | last post: by
7 posts views Thread by Patrick B | last post: by
2 posts views Thread by Kenneth P | last post: by
33 posts views Thread by gk245 | last post: by
8 posts views Thread by ajs | last post: by
5 posts views Thread by DBC User | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.