Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to call a method at a particular time and after that certain time of limit it will always be open.

Example:

RecentTime= 6/9/2015 AM 12:00:00

ExactTime when function will start working will be 6/10/2015 AM 10:30

Now I want like

C#
if(RecentTime >= ExactTime)
{
//Some Method
}



Thanks
Posted
Updated 9-Jun-15 20:10pm
v2
Comments
Tomas Takac 10-Jun-15 2:24am    
What's your problem? You have the two datetimes, you compare them in your code already. If you want to compare times only then I don't understand why the date parts are different.
itsathere 10-Jun-15 3:05am    
Q.can we add time in date?

Example:
Date=6/10/2015+10:30 AM
ramyajaya 10-Jun-15 2:30am    
You can use datetime. parse function using format passing make them as datetime and compare greater
itsathere 10-Jun-15 2:58am    
please explain..
ramyajaya 10-Jun-15 8:57am    
Check this to know how to Compare two date time inputs.
https://msdn.microsoft.com/en-us/library/system.datetime.compare%28v=vs.110%29.aspx
Use datetime. Now() to fetch the current time

Yes:
C#
DateTime recentTime = new DateTime(2015, 9, 6);
DateTime exactTime = recentTime.AddHours(10).AddMinutes(30);
if (DateTime.Now >= exactTime)
   {
   ...
   }
Or
C#
DateTime recentTime = new DateTime(2015, 9, 6);
DateTime exactTime = recentTime.AddMinutes(630);
if (DateTime.Now >= exactTime)
   {
   ...
   }
 
Share this answer
 
Comments
itsathere 10-Jun-15 3:54am    
It wil be better if i use Timespan

DateTime recentTime = DateTime.Now;
TimeSpan timespan = new TimeSpan(10, 30, 00);
DateTime Exdt = recentTime.Date.Add(timespan);
if(DateTime.Now>Exdt )
{

}

Btw Thanks.
C#
DateTime recentTime = DateTime.Now;
TimeSpan timespan = new TimeSpan(10, 30, 00);
DateTime Exdt = recentTime.Date.Add(timespan);
if(DateTime.Now>Exdt )
{

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900