how to get date to the datetime object when date is being selected in two datetimecontrol by runtime

Posted by Kumartyr under C# on 2/7/2014 | Points: 10 | Views : 1011 | Status : [Member] | Replies : 1
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




Responses

Posted by: Sravan661 on: 2/10/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Please use this code to get date in c#
dateTimePicker1.Value.Date

and compare them normally

Hope it helps you

sravan

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response