Skip to main content
edited tags; edited title
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Best Way TimeDiff Time difference

deleted 8 characters in body; edited tags; edited title
Source Link
BCdotWEB
  • 11.4k
  • 2
  • 28
  • 45

Best Way TimeDiff C#

I'm using DateTime C#. I have an XML file with attribute HOUR, i.e:

<MyXML>
     <LastTimeTaskRun>11:50</LastTimeTaskRun>
</MyXML>

And i have a task that running each 5 min. I want to know if the current time and the hour from the xml big then 5 min. What I'm trying:

int hour, min;
DateTime dateTimeXML = DateTime.Now, dateTimeNow;
string [] lastSuccessTime = LastSuccessTime.Split(':');

Int32.TryParse(lastSuccessTime[0], out hour);
Int32.TryParse(lastSuccessTime[1], out min);

dateTimeXML = dateTimeXML.Date + new TimeSpan(hour, min, 0);
dateTimeNow = DateTime.Now;

bool isBigThen5Min = (dateTimeNow - dateTimeXML).TotalMinutes > 5;

The code is works fine, but i want to know what is the best way (performance) to do that.

Thanks

Best Way TimeDiff C#

I'm using DateTime C#. I have an XML file with attribute HOUR, i.e:

<MyXML>
     <LastTimeTaskRun>11:50</LastTimeTaskRun>
</MyXML>

And i have a task that running each 5 min. I want to know if the current time and the hour from the xml big then 5 min. What I'm trying:

int hour, min;
DateTime dateTimeXML = DateTime.Now, dateTimeNow;
string [] lastSuccessTime = LastSuccessTime.Split(':');

Int32.TryParse(lastSuccessTime[0], out hour);
Int32.TryParse(lastSuccessTime[1], out min);

dateTimeXML = dateTimeXML.Date + new TimeSpan(hour, min, 0);
dateTimeNow = DateTime.Now;

bool isBigThen5Min = (dateTimeNow - dateTimeXML).TotalMinutes > 5;

The code is works fine, but i want to know what is the best way (performance) to do that.

Thanks

Best Way TimeDiff

I'm using DateTime C#. I have an XML file with attribute HOUR, i.e:

<MyXML>
     <LastTimeTaskRun>11:50</LastTimeTaskRun>
</MyXML>

And i have a task that running each 5 min. I want to know if the current time and the hour from the xml big then 5 min. What I'm trying:

int hour, min;
DateTime dateTimeXML = DateTime.Now, dateTimeNow;
string [] lastSuccessTime = LastSuccessTime.Split(':');

Int32.TryParse(lastSuccessTime[0], out hour);
Int32.TryParse(lastSuccessTime[1], out min);

dateTimeXML = dateTimeXML.Date + new TimeSpan(hour, min, 0);
dateTimeNow = DateTime.Now;

bool isBigThen5Min = (dateTimeNow - dateTimeXML).TotalMinutes > 5;

The code is works fine, but i want to know what is the best way (performance) to do that.

Source Link

Best Way TimeDiff C#

I'm using DateTime C#. I have an XML file with attribute HOUR, i.e:

<MyXML>
     <LastTimeTaskRun>11:50</LastTimeTaskRun>
</MyXML>

And i have a task that running each 5 min. I want to know if the current time and the hour from the xml big then 5 min. What I'm trying:

int hour, min;
DateTime dateTimeXML = DateTime.Now, dateTimeNow;
string [] lastSuccessTime = LastSuccessTime.Split(':');

Int32.TryParse(lastSuccessTime[0], out hour);
Int32.TryParse(lastSuccessTime[1], out min);

dateTimeXML = dateTimeXML.Date + new TimeSpan(hour, min, 0);
dateTimeNow = DateTime.Now;

bool isBigThen5Min = (dateTimeNow - dateTimeXML).TotalMinutes > 5;

The code is works fine, but i want to know what is the best way (performance) to do that.

Thanks