TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kumartyr
NA
55
27.9k
how to compare two dates in datetimepicker
Feb 7 2014 6:05 AM
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 from that controls, it should read the textfile(i.e) log.txt & search line by line get the matching of both these dates and as well as inbetween dates and write the data to a textbox or label control
for eg in log file the some data is like below
3/12/2013 2:51:47 PM - ASDASDASD.D20131203145019
4/12/2013 2:52:23 PM - ASDDFSDSA.C20131203145019
5/12/2013 2:52:37 PM - SDASAFAS_20131203182101.D
6/12/2013 3:17:11 PM - RRRTWEWA_20131203184602.D00
7/12/2013 3:35:32 PM - XBCNXCXCXC.D0120131203153408
if i search from 5 dec 2013 to 7 dec 2013
it should retrieve
5/12/2013 2:52:37 PM - SDASAFAS_20131203182101.D
6/12/2013 3:17:11 PM - RRRTWEWA_20131203184602.D00
7/12/2013 3:35:32 PM - XBCNXCXCXC.D0120131203153408
but uptonow i am getting
5/12/2013 2:52:37 PM - SDASAFAS_20131203182101.D
7/12/2013 3:35:32 PM - XBCNXCXCXC.D0120131203153408
i am retriving only the startdate & enddate matching data not inbetween date data
The below are some of the coding i have tried
string FDDate = FD.Date.ToString("M/d/yyyy");
string TDDate = TD.Date.ToString("M/d/yyyy");
string searchstring = EnterFileNameTextbox.Text.ToString();
string searchfromdate = FromDateTimePicker.Value.ToShortDateString();
string searchtodate = ToDateTimePicker.Value.ToShortDateString();
string line;
StringBuilder sb = new StringBuilder();
int counter = 0;
using (StreamReader file = new StreamReader(@"D:\log.txt"))
{
while ((line = file.ReadLine()) != null)
{
if (line.Contains(searchstring) && line.Contains(FDDate))
{
sb.AppendLine(line.ToString());
counter++;
}
else if (line.Contains(searchstring) && !line.Contains(FDDate))
{
if (FD.Date < TD.Date)
{
sb.AppendLine(line.ToString());
counter++;
FDDate = FD.Date.AddDays(1).ToShortDateString();
}
else if (FD.Date == TD.Date)
{
FDDate = FD.Date.ToShortDateString();
sb.AppendLine(line.ToString());
counter++;
}
}
}
}
ResultTextBox.Text = sb.ToString();
CountLabel.Text = counter.ToString();
}
catch (Exception ex)
{
MessageBox.Show("The file could not be read");
MessageBox.Show(ex.Message);
}
i am not getting idea to do the loop
Reply
Answers (
1
)
Out of Memory Exception while reading large XML file
C# XML Namespace