How to convert number to date

Hi,

I’m reading a date data from excel file and I got random number as output. I tried this expression but it’s throwing me this error :

image

date_auction_tmp = DateTime.FromOADate(Double.Parse(row.item(8).ToString))

date_auction_tmp is string type variable

How to solve it? Thanks :slight_smile:

@Rhys18 Try below solution

DateTime dt = DateTime.FromOADate(row.item(8).ToString)

Hi @Rhys18

Check the date_auction_tmp data type it should be DateTime Type

1 Like

Hey!

Try this:

DateTime.FromOADate(CDate(row.item(8).ToString("dd"))

Regards,
NaNi

Hi,

Changing from string to date time is working but other variable is having errors. Can it just be string var only?

This is throwing me error @THIRU_NANI

Could you please show us the value on which you are trying for conversion?

Hey!

Could you please provide us the input data?

Regards,
NaNi

Yes. Sure, Let me share it here.

I have a a data like this :

As it can be see, there’s a cell with double value (with / on the cell). So I’m trying to convert it using FromOADate and I got result like this :

image

For some reason the date is read as a random number and I need to get the left cell value of the data. I tried to change the excel format date into MM/dd/yyyy but because I have use split(var_date), it only take the month.

Hey @Rhys18

What’s the current setting for Preserve Format please ?

Thanks
#nK

Unchecked.
image

Hey @Rhys18

Could you please try enabling it once and see if you directly get the date itself in the DataTable ?

Thanks
#nK

image

Not working

Looks ike it is still coming as number only.

Please share the file here if possible without disclosing sensitive data.

Sure, here’s the data :
Auction date.xlsx (9.7 KB)

1 Like

hELLO @Rhys18

I hope you are reading the excel and trying to convert the value in excel to the datetime.
If you are reading the row it will be in string format, so you can watch the below video to convert it to datetime format.

Else you can use Modify date activity as well.

Hey @Rhys18

Please find the output with Preserve Format enabled,

Thanks
#nK