0
        #region XML Reader (Load the XML file)
        XmlDocument xdoc = new XmlDocument();
        xdoc.Load(root + infoFolder + "setting.xml");
        #endregion

        #region Find out if its time to update installation files
        var DateNow = DateTime.Now.ToString("yyyy-MM-dd");
        var LastUpdate = xdoc.SelectSingleNode("/Settings/TimeUpdated").InnerText;

        if (DateNow.CompareTo(LastUpdate) > 0)
        {
          MessageBox.Show ("Last time you updated you installation files was" + LastUpdate + ". Today its " + DateNow,("Its been 14days.(or more)"));
        }
        #endregion

This is what i came up with but, this only compare if 'Datenow' is higher then 'Lasteupdate' And i think CompareTo dont work with dates.

What i realy want to to compare Datenow and Lasteupdate and if its 14 days different, then show messagebox.

This is how i fixed the problem:

  #region Find out if its time to update installation files
            String LastUpdate = xdoc.SelectSingleNode("Knowhow/Settings/TimeUpdated").InnerText;

            DateTime dt1 = DateTime.Now.AddDays(-14);
            DateTime dt2 = DateTime.Parse(LastUpdate);

            String DateToday = dt1.ToString("yyyy-MM-dd");
            String DateINFO = dt2.ToString("yyyy-MM-dd");



            if (dt1.Date > dt2.Date)
            {
                MessageBox.Show("Last time you updated you installation files was" + DateINFO + ". Its been Its been 14days.(or more)");
                ;            }
            else
            {
                MessageBox.Show("Dont need to update");
            }

            #endregion
Tobbe
  • 23
  • 3
  • 2
    There are plenty of ways to find the difference between 2 dates, did you even search on it? – Shaharyar Feb 06 '16 at 19:42
  • Note that in your example, you're actually comparing `string` values. Instead, compare `DateTime` values, and add or subtract 14 days to one side of the comparison. – Matt Johnson-Pint Feb 06 '16 at 19:47

0 Answers0