Is it after midnight?

Using DateTime.Now how can I determine if it is after midnight?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
SRigneyConnect With a Mentor Commented:
You could use a separate time for this portion and just have it run once every 24 hours.

Otherwise you would want to do something like

// Initialize a default LastRun.  This will always run the first time.
// because the initialization will not be today.
DateTime LastRun = New DateTime();

in your timer function.

// Check if it's currently between midnight and 1 am.
if( DateTime.Now.Hour > 0 && DateTime.Now.Hour < 1  )
{
   // Make sure this has not run already today.
   if( DateTime.Now.Date > LastRun )
   {
      LastRun = Datetime.Now;
      // run the append process.
   }
}
0
 
chmohanConnect With a Mentor Commented:
u can use DateTime.Now.Hour.ToString() and  see if it is less than 12
or u can use DateTime.TimeOfDay Property
0
 
msdixonConnect With a Mentor Commented:
it's always after midnight. if it's before midnight it's yesterday.

ok, now for a serious answer. the hour should be 1 for 1 am instead of 13 for 1 pm
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Tom KnowltonWeb developerAuthor Commented:
I want to know if it is between 12 midnight and say, 1 AM.
0
 
Tom KnowltonWeb developerAuthor Commented:
>>>> it's always after midnight. if it's before midnight it's yesterday.


:)  smart a**!
0
 
Tom KnowltonWeb developerAuthor Commented:
A little more info on this.

I have a phone log file which is updated will call information throughout the day.

Add midnight, I want to take all call information older than 30 days and append it to another table.

The append part is already done....I just want to make sure the timing is correct.

This only needs to fire ONCE a day....between midnight and 1 AM, for example.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.