?
Solved

ASP.net converting data types

Posted on 2011-03-18
5
Medium Priority
?
354 Views
Last Modified: 2012-05-11
Hi
I have two fields in a SQL database that are of types: time(7) and date.
I am reading data out of Excel that needs to be converted to these formats.
What VB.net code would I use?
All I can find so far is a conversion to date and time  together
eg Dim oStartTime As String = Convert.ToDateTime(reader("Start time"))
0
Comment
Question by:Murray Brown
[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
5 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35167513
Hi,

The vb.net datatype equivalent for  Time datatype of sql Server  is TimeSpan ( http://msdn.microsoft.com/en-us/library/cc716729.aspx )

you can conver it like this, but you have to use the field INDEX instead of the field name

Dim tsStartTime As TimeSpan = CType(reader(indexofstarttimefield), TimeSpan)

0
 
LVL 11

Accepted Solution

by:
SAMIR BHOGAYTA earned 1000 total points
ID: 35167662
Hi,

Try this way

select convert(varchar(10),date1,101) as date1 from tb1 where convert(varchar(10),date1,101) = '08/24/1994'
0
 
LVL 13

Assisted Solution

by:gamarrojgq
gamarrojgq earned 1000 total points
ID: 35168888
Sorry I forgot the GetTimeSpan, here it is again

Dim tsStartTime As TimeSpan = CType(reader.GetTimeSpan(indexofstarttimefield), TimeSpan)
0
 
LVL 7

Expert Comment

by:foobarr
ID: 35168889
You could just convert the variable to a date string in the way you need it.

varToConvert

cdate(varToConvert).ToString("yyyy-MM-dd") -> Date is 2011-03-18

cdate(varToConvert).ToString("HH:mm") -> Time is military time
0
 

Author Closing Comment

by:Murray Brown
ID: 35168988
thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

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