Reputation: 4347
My Database stores time in the SQL DataType Time. I'm using mvc 3 in vb.net and trying to get the time to display in standard format (AM/PM). But, I keep getting an error "Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'."
This is the code I'm using
<h4>Tuesday</h4>
<ul>
@For Each c As ClassSchedule In ViewBag.Tuesday
@<li>@c.timeStart - @c.timeEnd - @c.name</li>
Next
</ul>
Any help is appreciated.
Upvotes: 1
Views: 657
Reputation: 2428
Edit:
@<li>
@(new DateTime(c.timeStart.Ticks).ToString("hh:mm:ss tt")) -
@(new DateTime(c.timeEnd.Ticks).ToString("hh:mm:ss tt")) - @c.name
</li>
Eror Occured becuse you subtract Dates
@<li>
<span>@c.timeStart </span>-
<span>@c.timeEnd </span>-
<span>@c.name</span>
</li>
Upvotes: 1
Reputation: 4347
Figured it out --- you have to convert the time into a string first
@
Upvotes: 0