Solved

Is it after midnight?

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

Assisted Solution

by:chmohan
chmohan earned 50 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 50 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:knowlton
ID: 11843234
I want to know if it is between 12 midnight and say, 1 AM.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Author Comment

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


:)  smart a**!
0
 
LVL 5

Author Comment

by: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 400 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
VB.NET HttpWebRequest 12 55
Parse the OuterHTML Data in the txtfile using c# 4 47
Linq Help 1 35
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now