Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.net converting data types

Posted on 2011-03-18
5
Medium Priority
?
357 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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