?
Solved

Convert OLE date, OLE time to a datetime object

Posted on 2006-06-30
4
Medium Priority
?
660 Views
Last Modified: 2012-08-13
Hey guys, I'm importing data from a foxpro database into Sql Server 2005 using vb.net.
I have two database columns, a date, and a time, which I need to convert (SAFELY) to a .net DateTime object.

I was thinking of just directly equating the DateTime = dr("Date")
then doing a parse of the time.tostring to correctly obtain the time information.

Is this the best way to do this, or have I missed a good little function for this?  I'm watching this like a hawk :)
0
Comment
Question by:spinalogic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 10

Expert Comment

by:ericwong27
ID: 17022863

 A return value indicates whether the conversion succeeded or failed.
 Dim lDateValue As Date
 If Date.TryParse(dr("Date").ToString, lDateValue) = False Then
    ....
 End

0
 

Author Comment

by:spinalogic
ID: 17025061
I need the datetime as one object
so a date
and a time
into a vb.net datetime
0
 
LVL 10

Accepted Solution

by:
ericwong27 earned 2000 total points
ID: 17025469
Assume the date and time col are string data type and the format is dd-MM-yyyy and HH:mm:ss


 Dim dt As DataTable =  GetData
        Dim sysDatetime As String = String.Format("{0} {1}", dt.Rows(0)("SysDate").ToString, dt.Rows(0)("SysTime").ToString)
        Dim myDateTime As DateTime = DateTime.ParseExact(sysDatetime, "dd-MM-yyyy HH:mm:ss", Nothing)
        Debug.WriteLine(myDateTime.ToString("dd-MMM-yyyy hh:mm:ss"))
0
 

Author Comment

by:spinalogic
ID: 17028231
Didn't know you could do the parameter stuff in VB for strings. I'm from a Java/C background.  Cheers for a great answer.

We're reverse engineering a database and the idiots stored the time a freaking DECIMAL.  Hence my problem and asking for help, but you certainly did answer the question hence obtaining points.  :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question