I'm trying to make this thing were when it is a certain time a label will turn red. So if lunch is 12:00-12:30 the label lunch will turn red for that time.
You should be more precise with your questions. What are you having trouble with? Finding out the time? Changing the color of the label? Windows Forms? Changing the label color? All?
You posted no code, so we can't use that to get a better picture of how to help you. Have you tried anything so far?
For the time, check out the DateTime struct (scrol down for some examples). For the label color, change the ForeColor property of the label (assuming you're using Win Forms).
The DateTime structure has a static property Now which let's you get the current date and time. Once you obtain it, you can compare it to other values. Simply use two DateTime member variables in your form class to store the start time and the end time.
Code:
DateTime date1 = new DateTime(2012, 6, 25, 12, 0, 0); // 6/25/2012 12:00:00 -- make sure it's a class member variable
/* Parameters:
year
Type: System.Int32
The year (1 through 9999).
month
Type: System.Int32
The month (1 through 12).
day
Type: System.Int32
The day (1 through the number of days in month).
hour
Type: System.Int32
The hours (0 through 23).
minute
Type: System.Int32
The minutes (0 through 59).
second
Type: System.Int32
The seconds (0 through 59).
*/
You can use a timer that ticks at a certain interval to check the date & time with DateTime.Now. Drag the timer from the toolbox, and handle it's Tick event, by comparing the values stored with the value returned by DateTime.Now. Also, make sure that the timer is started once you run your app.
You can ignore dates if they aren't needed, but you'll need to create a custom comparison method then.
Bookmarks