Reputation: 329
Hello i want to display the datetime2(7) that is coming from my db 1900-01-01 02:15:00.0000000
to 02:15 PM
and also want that when the data is not coming from db i will print N/A. How this can be possible
I use this <%# DateTime.Parse(Eval("PICKTIME").ToString()).ToString("hh:mm tt")%>
in above code if the value is coming NULL then its give me exception
So i use this
'<%#(String.IsNullOrEmpty(Eval("readyTime").ToString()) ? "N/A" : Eval("readyTime"))%>'
but problem is that it print 1900-01-01 02 :15:00
if value is not coming then NULL
. But i want 02:15
if not any Value then NULL
Upvotes: 1
Views: 115
Reputation: 9479
Why convert it to a date? It is datetime that is padded with zeros, making it easy to parse with string functions.
String.IsNullOrEmpty(Eval("readyTime").ToString()) ? "N/A":Eval("readyTime").ToString().Substring(12,5)
Upvotes: 1