Solved

Is it after midnight?

Posted on 2004-08-19
6
787 Views
Last Modified: 2012-08-14
Using DateTime.Now how can I determine if it is after midnight?
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Tom Knowlton
ID: 11843234
I want to know if it is between 12 midnight and say, 1 AM.
0
Independent Software Vendors: 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!

 
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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need to convert function to c# 5 54
C# Windows app updating JSON file error. 9 48
c#, datatable, aspx 4 47
How to set focus on a dynamic control 18 47
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

738 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