![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 378
Rep Power: 3
![]() |
C# Datetime data types
I have 2 questions about datetimes in C#. First, I want to compare the current date and time to a date and time I have previously defined to see if they match. I compare the dates once a minute using a timer. My problem is the 2 times never match because the seconds don’t match. When I define the datetime I want to compare to the current datetime, I set the seconds to 00, but when the timer compares the current time to that, chances are it wont be right on the minute so they won't match. Here is the code I am using:
// "date" is my already defined date
if (System.DateTime.Now == date)
{
// do stuff
}// "date" is my already defined date
if ((System.DateTime.Now.Year == date.Year)
&& (System.DateTime.Now.Month == date.Month)
&& (System.DateTime.Now.Day == date.Day)
&& (System.DateTime.Now.Minute == date.Minute))
{
// do stuff
}My second question is how do I subtract say 10 minutes off an already defined datetime variable? Thanks in advanced!
__________________
I am Addicted to Linux! |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|