Solved

Convert OLE date, OLE time to a datetime object

Posted on 2006-06-30
4
655 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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