Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net converting data types

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"))
Avatar of gamarrojgq
gamarrojgq

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)

ASKER CERTIFIED SOLUTION
Avatar of SAMIR BHOGAYTA
SAMIR BHOGAYTA
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Murray Brown

ASKER

thanks