Solved

Convert OLE date, OLE time to a datetime object

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now