Solved

Convert OLE date, OLE time to a datetime object

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GridDataView 6 44
Asp/Net Validation date Issue 9 38
.Net Web Site Password specs 2 20
Crystal Report for VS2013 17 42
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

20 Experts available now in Live!

Get 1:1 Help Now