How to convert string data into time format
I have some of the old data looks like this. And this is time data.
144601
170320
083345
I wanted to convert this in proper format as time with AM, PM etc. and display in GridView column.
Currently this data is displaying as it is in one of the GridView column
Please help out..
thanks
Public Function stringtodate(ByVal strdate As String) Dim tempdt As Date tempdt = Convert.ToDateTime(strdate) Dim format1 As String Dim en As New CultureInfo("en-AU") format1 = "MM/dd/yyyy HH:mm:ss" Dim dtstring As String dtstring = tempdt.ToString(format1) tempdt = DateTime.ParseExact(dtstring, format1, en.DateTimeFormat) Return tempdt End Function
you can specify the format as u need.How do I call this function in gridview, to display the data in one of the column of the grid view. ?
Use Bound column of grid.Now in datafield property try to bind the data using a literal.
<asp:literal id="datevar" runat="server">
<asp:grid>
<asp:boundcolumn ......datafield=<%= datevar %>
</asp:grid>
Now in code behind try to bind the your date value by calling that function to the datevar literal in grid_databound event.
Labels: 144601170320083345i, ado, convert, format, net, old, proper, string, time
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home