Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is it after midnight?

Posted on 2004-08-19
6
Medium Priority
?
812 Views
Last Modified: 2012-08-14
Using DateTime.Now how can I determine if it is after midnight?
0
Comment
Question by:Tom Knowlton
6 Comments
 
LVL 1

Assisted Solution

by:chmohan
chmohan earned 200 total points
ID: 11843181
u can use DateTime.Now.Hour.ToString() and  see if it is less than 12
or u can use DateTime.TimeOfDay Property
0
 
LVL 9

Assisted Solution

by:msdixon
msdixon earned 200 total points
ID: 11843198
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
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 11843234
I want to know if it is between 12 midnight and say, 1 AM.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 11843244
>>>> it's always after midnight. if it's before midnight it's yesterday.


:)  smart a**!
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 11843336
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
 
LVL 15

Accepted Solution

by:
SRigney earned 1600 total points
ID: 11843869
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question