Modifying DateTime 
Author Message
 Modifying DateTime

Hello,

what is the best to modify a DateTime variable? For example I need to set a
DateTime variable to the next full hour after DateTime.Now. Hour, Minute and
Second are readonly properties, so I guess I have to use AddMinutes(-Minute)
to set Minute to zero. I also tried the Ticks property, or setting each part
of the time in the constructor, but it all looks a bit overcomplicated for
what I'm trying to do. Is there an easy, short, clean solution?

Jens



Sat, 20 Nov 2004 00:17:20 GMT  
 Modifying DateTime
P.S. This is the best solution I found. Someone knows a better one?

DateTime n = new DateTime(DateTime.Now.Ticks);
DateTime d = new DateTime(n.Year, n.Month, n.Day, n.Hour + 1, 0, 0);



Sat, 20 Nov 2004 00:20:18 GMT  
 Modifying DateTime
Jens,

    You can always create a new instance of the TimeSpan structure and add
that to the DateTime structure.  That will give you a new DateTime structure
that has the original DateTime with the TimeSpan added.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hello,

> what is the best to modify a DateTime variable? For example I need to set
a
> DateTime variable to the next full hour after DateTime.Now. Hour, Minute
and
> Second are readonly properties, so I guess I have to use
AddMinutes(-Minute)
> to set Minute to zero. I also tried the Ticks property, or setting each
part
> of the time in the constructor, but it all looks a bit overcomplicated for
> what I'm trying to do. Is there an easy, short, clean solution?

> Jens



Sat, 20 Nov 2004 00:30:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to subtract one DateTime from other DateTime?

2. Uptime/CIM datetime to DateTime conversion

3. how to convert string in listbox with datetime format to Datetime datatype

4. MS Access datetime & COleVariant datetime vs SQL Server 2000 datetime

5. Help: WSDL util for .NET converts nillable xsd:dateTime -> System.DateTime which is not null

6. Getting datetime form SQL, ADO returning datetime, how to convert it in time_t ?

7. Problem with C# System.DateTime variable assignment to SqlDataType.DateTime SqlParameter for a SQL Server stored procedure

8. DateTime.ToString

9. DateTime in ODBC.net

10. Debugger does not show time of DateTime variable

11. DataGrid DateTime question

12. DateTime.Now()

 

 
Powered by phpBB® Forum Software