I have a XML file with these datetime. Is it possible to get the time difference between the latest time with the previous time?
Ex: In this pic, latest time is 10/27/2021 09:15, previous time is 10/26/2021 16:52, so I want to get the difference in these two times and run something behind the time difference if the time difference more than 2 hours. Picture 1
while, this time, latest time become 10/27/2021 10:32, previous time is 10/27/2021 09:15, I need to compare with these two this time. If the time difference is not more than 2 hours, then do nothing. Picture 2
I had try and save the datetime in the XML file.
string xmlFilePath = Directory.GetCurrentDirectory() + @"\database.xml";
XDocument doc;
try
{
doc = XDocument.Load(xmlFilePath);
}
catch
{
doc = new XDocument(new XElement("DateTime"));
}
XElement time = doc.Element("DateTime");
time.Add(new XElement("dateTime",
new XElement("LastRunTime", DateTime.Now.ToString("g", DateTimeFormatInfo.InvariantInfo))));
doc.Save(xmlFilePath);
Any suggestion/idea on the next step to get the time difference that stored in the XML file?