Solved

Convert OLE date, OLE time to a datetime object

Posted on 2006-06-30
4
648 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
  • 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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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