Solved

Is it after midnight?

Posted on 2004-08-19
6
775 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

11 Experts available now in Live!

Get 1:1 Help Now