473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 15815
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Manish Jain | last post by:
Platform : ASP.Net/C# void SomeFunction(DateTime date) { string text = date.ToString(); //This crashes if date is null } I am using a construct similar to above. I want to check if the date...
7
by: Patrick B | last post by:
Say I have three DateTime variables: DateTime A; DateTime B; DateTime C; How can I assign to C just the date part of A and just the time part of B? Something like this...
2
by: Kenneth P | last post by:
Hi, I'm trying to use MySql 4.1 db instead of MSSql2k and am having problems with the DateTime in the db. In mysqladmtools 1.0.19 I'm recommended to use 0000-00-00 00:00:00 as the default...
33
by: gk245 | last post by:
I mean, anything that follows a 0 is automatically turned into a octal number. I want to have a integer variable that will hold numbers as integers even if they begin with a zero. for example:...
8
by: ajs | last post by:
I have a process that verifies that a server is running. If the server stops responding I send an email to a support person. Now I want to add a downtime indicator so that my code does not send...
0
by: DeePeeJay | last post by:
Hello, Is there a better way to convert separate integer values, representing Day, Month, Year, Hour, Minute and Second to DateTime? I work in the Automation Industry and PLC (Programmable...
2
by: Mike | last post by:
Hi, I have DateTime filed in db table. I'd like to search my db based on DateTime filed, actually to list all rows with particular date, for e.g. 16.11.2007... I send string to method for....
5
by: DBC User | last post by:
How would you develop a zero footprint application, is the smart client application a zero footprint application? Thanks.
1
by: almurph | last post by:
Hi, I have a list object called "myList" with the first item a string and the second a DateTime. Something like this: "some text 1", 19/03/2008 12:56:36 "some text 2", 19/03/2008 10:56:36...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...
1
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
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.