Solved

ASP.net converting data types

Posted on 2011-03-18
5
328 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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).

863 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

25 Experts available now in Live!

Get 1:1 Help Now