VB.NET convert Integer to Date

In VB.NET, I have a Integer value like 41498. I'm trying to convert that to a Date value, which should end up being 08/12/2013.

In VBA I'd do this:

CDate(41498)

And my result would be as expected (08/12/2013).

In VB.NET, I get an error:

"Value of type 'Integer' cannot be converted to 'Date'"

I've looked into the ParseDate and such, and cannot get those to function correctly.

How can I convert my Integer value to a Date?
LVL 86
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
How do you figure 41498 = 08/12/2013?
0
Robert SchuttSoftware EngineerCommented:
Try this:
Dim d As Date = Date.FromOADate(41498)

Open in new window

either using Date or DateTime
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareAuthor Commented:
Perfect! Thanks for the quick solution.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareAuthor Commented:
paulmcd:

The value came from an Excel spreadsheet, and it was originally formatted as 08/12/2013. When pulled in (through another process over which I have no control), it is reformatted as 41498. I believe that is the number of days from the default date in Excel, which is  1/1/1900 (with some accounting for "bugs" in the original design: http://www.cpearson.com/excel/datetime.htm)
0
Paul MacDonaldDirector, Information SystemsCommented:
"...the number of days from the default date in Excel, which is  1/1/1900..."
That was my question.  Different applications measure time differently - UNIX, for instance, measures the number of seconds since 1/1/1970.  

In this case, as long as Excel and the .NET Framework both use the same starting point, you should be okay.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.