Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8597571

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:56:35+00:00 2026-06-12T00:56:35+00:00

I am reading a csv file which has following data format 14-Sep-12 ALUMINI 31-Dec-12

  • 0

I am reading a csv file which has following data format

14-Sep-12   ALUMINI 31-Dec-12   117.65  119.25  117.65  118.9   116.75  36
14-Sep-12   ALUMINI 30-Nov-12   116.95  118.65  116.8   118.4   116.5   252
14-Sep-12   ALUMINI 31-Oct-12   116.45  118.15  116.05  117.85  116.05  2802

I am reading this data with following code

List<string> sc = new List<string>();
filepath = "abc.csv" ;

FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs);

if (fs != null)
{
  while ((oneLine = sr.ReadLine()) != null)
  {
     sc.Add(oneLine);
  }

  sr.Close();

  // Now writing above data in  some file , fo and fout are already declared 
  fo = new FileStream("tempd.txt", FileMode.Append, FileAccess.Write);
  fout = new StreamWriter(fo);

  foreach (string str in sc)
  {
    // i am using ' ' as one of my splitter character
    char[] splitter = { ' ', ',', '\t' };
    string[] sa1 = str.Split(splitter);

    string wline = sa1[0] + "," + sa1[1] + "," + sa1[5] + "," + sa1[6] + "," + sa1[7] ;
    fout.WriteLine(wline);
  }
  fout.Close();
}

My biggest problem is first column of of data is 14-Sep-2012 has been changed to 14 Sep 2012 (- is missing). Which is creating problem in my rest of application.

Is there any way by which I can convert date format while reading and writing file, I want to store this date 14-Sep-2012 as 2012-9-14.

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:56:36+00:00Added an answer on June 12, 2026 at 12:56 am

    I think this is the answer you are looking for.

    DateTime d = Convert.ToDateTime(sa1[0]);
    
    string wline = d.ToString("yyyy-MM-dd") + "," + sa1[1] + "," + sa1[5] + "," + sa1[6] + "," + sa1[7];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a local csv file which has data and I will eventually use
I have a System.Data.DataTable which is populated by reading a CSV file which sets
I have .zip file which contain csv data. I am reading .zip file using
I'm reading in a csv file of time-series data into a C++ program. My
I have a BAT file, which creates a number of csv files by reading
Say I have a sample file sample.csv: row,col,value 1,1,2 1,2,3 1,3,NA When reading data
I have a csv file which has 3 columns. I am trying to search
I'm running several scripts which are writing and reading from the same CSV file
I am reading a following CSV file in java and 1191196800.681 - !AIVDM,1,1,,,13aG?N0rh20E6sjN1J=9d4<00000,0*1D Here
I am importing data from a CSV file using fgetcsv(), which yields an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.