hey friends i am reading a csv file and i have to read a specifice coloumn form the file and that coloumn contains date and i have to read the date first and then keep a validation that if the dates in the file are between some dates then the program will read data from another file . The csv file contains a header and that creates a problem while reading the first row the file the file data is like this:
start_date_time,ani,dialed_digits,actual_dur,rounded_dur_secs,cost
"03/01/2008 00:05:57",629172162448,"923455755684",2,2,0.002800
"03/01/2008 00:15:56",79279906564,"79278454880",51,60,0.135000
"03/01/2008 00:16:51",4166143724,"92922202502",188,188,0.256900
"03/01/2008 00:23:13",07956563557,"925871021085",1020,1020,1.393400
"03/01/2008 00:38:13",639262060046,"923084230440",1,1,0.001400
"03/01/2008 00:47:02",--------------,"92945623075",124,124,0.169400
"03/01/2008 01:08:14",7187696383,"92946725834",457,457,0.624300
The code of mine goes here
static void Main(string[] args)
{
StreamReader sr = new StreamReader(@"C:\Documents and Settings\jitendra\Desktop\ric_mar.csv");
StreamWriter sw = new StreamWriter(@"C:\dates.txt");
string dates = "";
string[] dvalue = null;
IList<string> list = new List<string>();
while (!sr.EndOfStream)
{
dates = sr.ReadLine();
dvalue = dates.Split(',',';');
if (dvalue.Length > 3)
{
list.Add(dvalue[0].Replace("\"",""));
}
}
DateTime begin = new DateTime(2008, 3, 1);
DateTime end = new DateTime(2008, 3, 9);
foreach (string var in list)
{
DateTime datevalue = DateTime.ParseExact(dvalue[0].ToString(), "3/1/2008 00:00:00", null);
//DateTime datevalue = DateTime.Parse(var);
Console.WriteLine(datevalue.ToString());
Console.ReadLine();
sw.WriteLine(var.ToString());
}
sw.Flush();
sw.Close();
}
}
}