Write todays date without time stamp into a cell in excel file

Hello Everyone,

I am trying to write today’s date into a cell in excel file using write cell activity. I am using System.Date.Now.ToString(“MM/dd/yyyy”) as value. While running/debugging I can see that i am getting only date without any timestamp where as when i am writing it on excel it is printing as below.

To be written in Excel
Expected : 12/16/2021
Actual : 12/16/2021 0:00 (0:00 referring as 12:00:00 AM)

Atlast i am writing this data into a csv file using Write CSV activity

Could someone help me on this to only write date, month and year not time stamp @Palaniyappan @Lahiru.Fernando or anyone. Thanks

Hi,

i think it is because of excel format whenever we insert the value through write cell or whatever method it automatically turn into that format.

if you are using just template excel to store the values we can change the format to the excel as one time activity so that it will not create any time stamp. thanks.

1 Like

Hi @kirankumar.mahanthi1

could you please provide steps after creating excel how to change the format of the particular column?

Thanks

Hi,

Before going to that step may i know what is the logic you are using to write the date info into the excel.

Hi @kirankumar.mahanthi1

I am just using write cell activity to that particular column in excel application scope activity. Please find below screenshot for reference.

image

Hi Satish,

Could you please try with the below simple vb code(invoke code activity) to convert the format of the column. Replace the A column with your column.

Dim excel As Microsoft.Office.Interop.Excel.Application
Dim wb1 As Microsoft.Office.Interop.Excel.Workbook
Dim ws1 As Microsoft.Office.Interop.Excel.Worksheet
excel = New Microsoft.Office.Interop.Excel.ApplicationClass
wb1 = excel.Workbooks.Open(Your work book path)
ws1 = CType(wb1.Sheets(Your work sheet), Microsoft.Office.Interop.Excel.Worksheet)
ws1.Range(“A:A”).NumberFormat = “MM/dd/yyyy”
wb1.Save
wb1.Close
excel.Quit
ws1 = Nothing
wb1 = Nothing
excel = Nothing
GC.Collect

And also please review the below new activity called Format cells. thanks.

Hi Kiran,

I’ve tried the given code but I am getting below error saying excel application was not defined. Please find below screenshot for reference.

Hi @satishmypudi

Instead of using Excel scope Application you can try with Workbook “Write Cell”

Regards
Gokul

Hi,

Please import the following package microsoft.office.interop.excel . once you import this package you will not get error. thanks

Hi Gokul,

I am sorry and forgot to mention that, i am working on csv file. if i use workbook it may lead to double steps. could you please provide me any alternative steps?

Thanks kiran
I will try and let you know

Excel automatically detects what type of data it is and formats it. Right-click the cell in Excel and choose “format cell” and you’ll see it.

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