Date format changing while exporting from sql to excel

hi,
I am exporting data from sql to excel. but problem is that while exporting time column getting convert into 12 hour format . i have this format in sql- “02-11-2025 13.41.03” but in excel its showing -“02-11-2025 01.41.00 PM”.

how to solve this problem.

Are you using Write Range Workbook or Excel Activities? and are you saving the datable into excel or individual values to a cell ?

@Hemant_Deshmukh,

The DateTime format shown in the excel gets inherited from system DateTime format.

You will have to format the column to desired format using Format cells activity

Select Format data as type property to custom and provide this format

MM-dd-yyyy hh.mm.ss AM/PM

yes i am using write range to paste data to excel.

expected format is this 02-11-2025 13.41.03

@Hemant_Deshmukh

Use this format

MM-dd-yyyy hh.mm.ss

Hi @Hemant_Deshmukh

If formating does not work you can do post changes with a Linq

dt_Result=dt_InputData.AsEnumerable().Select(Function(row) dt_InputData.Clone.LoadDataRow( New Object(){
row("Column1").ToString,
row("Column2").ToString,
DateTime.ParseExact(row("DateColumn").ToString(),"dd-MM-yyyy hh.mm.ss tt", System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yyyy HH.mm.ss") },
False)).CopyToDataTable()

Sample input and output:


image

Hope this helps!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.