views:

48

answers:

2

I am making an application which requires entering time into the system. I made the time field in the database as nvarchar(5). When I input data into this field using the form in the application it is entered as a string is there a way in which I can convert it into a string into time format?

+2  A: 

You could use the DateTime.Parse(String) method. That will return you a DateTime struct.

There are plenty of Date and Time manipulation methods on this struct that you can use. See the link to MSDN for plenty of examples on how to format the date in a variety of ways.

http://msdn.microsoft.com/en-us/library/system.datetime.aspx

Ben Cawley
+2  A: 

You can use DateTime.Parse to convert the string into a DateTime type if the string is in a "known" format.

Or you can use DateTime.ParseExact(dateString, "ddd, dd MMM yy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) to specify your own input format.

JWL_