Sign in to follow this  

[.net] VB.NET - Modify the date part of a DateTime object?

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On startup my program reads in a DateTime value from the registry. What I need to do is to compare the time part of this DateTime value with the time part of DateTime.Now(). There doesn't seem to be an easy way to do this directly so I figured it would be a good idea to load the DateTime value from the registry and right after loading it, change the date part of the loaded DateTime to match DateTime.Now(). After attempting this I found that the properties of the DateTime object that I would have changed were read only. Is there an easy way to modify a DateTime object like this? If so how? Thanks! [Edited by - InsaneBoarder234 on June 14, 2006 9:45:55 AM]

Share this post


Link to post
Share on other sites
On the DateTime object is a property called TimeOfDay which returns an TimeSpan object. The TimeSpan class contains a static "Compare" method which compares 2 TimeSpan objects.
(Sorry, I'm a vb.net guy)

//The DateTime object from your registry
dim dt as Datetime = //get the value

dim compareValue as integer
compareValue = TimeSpan.Compare(dt.TimeOfDay, DateTime.Now.TimeOfDay)



Lookup MSDN to get details about the returnvalue of the compare method

Share this post


Link to post
Share on other sites

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this