Solved

ASP.net converting data types

Posted on 2011-03-18
5
348 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:murbro
[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 250 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 250 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:murbro
ID: 35168988
thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net web app 3 58
T-SQL: How to extract records into a new table 7 44
Shared Service Environment 2 54
How does this modal work? 3 33
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …

732 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