0

I'm using SqlBulkCopy to save a read-only Excel sheet into a predefined SQL table.
There are several date columns in the sheet, but not all the rows have date values(empty and '#').
The corresponding columns types are varchar(20) and not smalldatetime, because otherwise I get an error that the data can not be converted.

After running SqlBulkCopy the dates are saved as numeric values in a pattern that I can't figure out.
For example:
31.12.2010 is saved as 40543
31.13.2011 is saved as 40908
30.6.2011 is saved as 40724

Now I have to present the date in web forms. The numeric values don't bother me as long as I can convert them back to date format for presenting in a GridView, but I don't know how.

Would appreciate any help with this.

2 Answers 2

1

Try running this query:

SELECT CAST(CAST(YourVarcharDateColumn AS int) AS DateTime) FROM YourTable
1
  • this query returns the wrong value of the date. it always deviates a few days. Jun 25, 2013 at 8:21
0

I used the following:

DateTime.FromOADate(num).ToShortDateString();

where num is the numeric value of the date

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.