I am doing Windows project, in which I have two DateTimePicker controls, one for StartDate and other for EndDate.
In runtime, when user selects the StartDate and EndDate
I would recommend using DateTime.TryParse
(doc here) instead of just converting. That will allow you to provide valid formatting, handle failures (convert will throw if it fails).
The part about using the Date property seems fine, and comparison operators will work as expected.
Try and deal with DateTime datatypes here rather than converting everything to string. After reading the line from the file, parse out the date. Assuming it is always going to be the first element in the file, and is followed by a space, you could do this by using DateTime lineDate = DateTime.Parse(line.Split(" ")[0]);
Once you have the date from the file in that format, and you have DateTime fromDate
and DateTime toDate
obtained from your date pickers, you can write if(lineDate >= fromDate && lineDate <= toDate) sb.AppendLine(line);