I made this code:
string[] liness = File.ReadAllLines(ofd.FileName);
if (liness.Length > 0)
{
string lastLine = liness[liness.Length - 1];
string[] columns = lastLine.Split(';');
if (columns.Length > 0)
{
string date = columns[0];
//string lastColumn = columns[columns.Length - 5];
//ReaderRichTxtBox.Text = date;
string dateString = date;
dateString = dateString.Remove(19);
DateTime dateValue = DateTime.ParseExact(dateString, "dd/MM/yyyy HH:mm:ss", CultureInfo.CurrentCulture);
if (dateValue.Date.TimeOfDay == DateTime.Now.Date.TimeOfDay)
{
MessageBox.Show("OK");
}
else
{
MessageBox.Show("BAD");
}
I need to get last row and the first column of a txt file.
The txt file is something like this:
21/05/2020 17:05:00 ; info ; info ; info
and I need just the 21/05/2020 17:05:00
. I've done this part as you can see.
Now I have the variable dateString
that contains the date and hour of my txt file and I need to compare it with date and hours of Windows. I tried it as you can see, but it compare just the date and not the hours.
How can I compare the date and the hour of my txt file with date and hour of Windows? How should the code be? It is better for me if it doesn't consider the milliseconds.