Shane Nicholson

Shane Nicholson

  • 1.9k
  • 36
  • 574

Windows Application date format output

Nov 26 2020 6:24 AM
Good afternoon all,
 
I have made a windows form application that allows my user to insert some data and when "insert" is selected, the data is saved to my drive as a CSV file.
This all works fine. However, I need to date format to save in the CSV file as yyyy-MM-dd, as Tableau is reading it. 
I am very much a beginner and this is my first project, so please be gentle. I am using a dateTimepicker for my user to select the date.
Attached is my code to export to csv. I have tried Tostring("yyyy-MM-dd") and this did not work.
 
Thank you so much for your help.
 
Best regards,
 
 
"Excel.Workbook xlworkbook;
Excel.Worksheet xlworksheet;
object misValue = System.Reflection.Missing.Value;
xlworkbook = xlap.Workbooks.Add(misValue);
xlworksheet = (Excel.Worksheet)xlworkbook.Worksheets.get_Item(1);
Excel.Sheets worksheets = xlworkbook.Worksheets;
worksheets[3].Delete();
worksheets[2].Delete();
xlworksheet.Cells[1, 1] = textBox1.Text;
xlworksheet.Cells[1, 2] = ((DateTime)dateTimePicker1.Value).ToString("yyyy-MM-dd");
xlworksheet.Cells[1, 3] = textBox2.Text;
xlworksheet.Cells[1, 4] = textBox3.Text;
xlworksheet.Cells[1, 5] = textBox4.Text;
xlworksheet.Cells[1, 6] = textBox5.Text;
xlworksheet.Cells[1, 7] = textBox6.Text;
xlworksheet.Cells[1, 8] = textBox7.Text;
xlworksheet.Cells[1, 9] = textBox8.Text;
xlworksheet.Cells[1, 10] = textBox9.Text;
xlworksheet.Cells[1, 13] = textBox10.Text;
xlworksheet.Cells[1, 11] = comboBox1.Text;
xlworksheet.Cells[1, 12] = comboBox2.Text;
xlworkbook.SaveAs(@"\\172.21.4.14\BusinessLanding\BusinessLanding_Sync\operations_sync\FlightPlanning\savings_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv", Excel.XlFileFormat.xlCSVWindows);
xlworkbook.Close(true);
xlap.Quit();"
 
 

Answers (5)