By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

Timer.Elapsed on Date Change (millsecs)

P: n/a
ugh. Okay, I need to figure out the number of milliseconds between
DateTime.Now and the end of the day so that I can make changes based on
the date roll-over. I need to implement a Timer so that I can process
things on the Timer.Elapsed event that would happen right at the date
change (unless there is a better suggestion to implement an event on
the date change). DateTime isn't so friendly to this calculation.
Please, any suggestions are welcome. Preferably something efficient
and Threadsafe. VB.net is fine but C# is my current language.

Cheers and Thank you. This is bugging me!

Russ

Aug 10 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It all depends on what you mean by 'right at the date change'.

If you mean within a few seconds of midnight then it is relatively easy.

Create a timer with an interval of, say, 10 seconds.

Directly before starting the timer, store Now in a variable with scope
sufficient so that the timer elapsed event handler can see it.

In the timer elapsed event handler if the date part of Now is different than
the date part of the stored value then the date has changed.
<rh****@axys.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
ugh. Okay, I need to figure out the number of milliseconds between
DateTime.Now and the end of the day so that I can make changes based on
the date roll-over. I need to implement a Timer so that I can process
things on the Timer.Elapsed event that would happen right at the date
change (unless there is a better suggestion to implement an event on
the date change). DateTime isn't so friendly to this calculation.
Please, any suggestions are welcome. Preferably something efficient
and Threadsafe. VB.net is fine but C# is my current language.

Cheers and Thank you. This is bugging me!

Russ

Aug 10 '05 #2

P: n/a
Thanks for the suggestion. A friend sent me this:

public long MillisecsToNextDay()
{

DateTime dteCurrent = DateTime.Now;
DateTime dteTomorrow = DateTime.Today.AddDays(1);

long lgnValue = dteTomorrow.Ticks - dteCurrent.Ticks;

return (lgnValue/1000);

}
You could also use the number of Ticks in a day (86400000000) and do
something like this:

86400000000 - DateTime.Now.Ticks

Cheers!
Russ

Aug 10 '05 #3

P: n/a
oops. scratch the last part of that suggestion (86400000000 -
DateTime.Now.Ticks )...

Russ

Aug 10 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.