how to Sort date of format MM/dd/yyyy in datatable??
how to Sort date of format MM/dd/yyyy in datatable??
pushkar1008
Posts: 4Questions: 1Answers: 0
I have a datatable, I am loading data from MySql database into it. It has 3 date columns of format MM/dd/yyyy, sorting of all other columns is working fine, but it is not working correctly for date columns, it is sorting date like string, its not considering date and year, please help, How to sort date which is in MM/dd/yyyy format??
This discussion has been closed.
Answers
See this blog post.
Allan
Hey allan, Thank you for your response, I tried it already but its not affecting at all on my datatable, I dont know why... can you please tell me step by step process to to make MM/dd/yyyy date sorting correct..please
when I canged the format of Date boundfield which is in my Gridview to yyyy/MM/dd, it works fine, but its not sorting correctly when the format is MM/dd/yyyy... please help
I am trying to show you I did in brief, It is as follows,
//Script that initialises datatable
$(function () { $('[id*=grd_LeadList]').DataTable({ "responsive": true, "sPaginationType": "full_numbers" }); });//grd_LeadList Gridview design
<asp:GridView ID="grd_LeadList" HorizontalAlign="Center" AutoGenerateColumns="False" CssClass="display grid table table-hover table-striped table-bordered" runat="server" Visible="false" DataKeyNames="soli_id" OnRowCommand="grd_RowCommand" OnRowDataBound="grd_LeadList_RowDataBound"> <%--OnPageIndexChanging="grdView_PageIndexChanging" EnableViewState="true" AllowPaging="true" PageSize="20"--%>
<Columns>
<asp:BoundField HeaderText="soli_id" DataField="soli_id" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="Small" ItemStyle-CssClass ="hide" HeaderStyle-CssClass ="hide"/>
<asp:BoundField HeaderText="Added Date" DataField="sdate" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="Small" HeaderStyle-CssClass="align" HeaderStyle-Width="8%" DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField HeaderText="Release Date" DataField="rel_date" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="Small" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="align" HeaderStyle-Width="8%"/>
<asp:BoundField HeaderText="Due Date" DataField="due_date" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="Small" DataFormatString="{0:MM/dd/yyyy}" HeaderStyle-CssClass="align" HeaderStyle-Width="8%"/>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#61A2B0" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#61A2B0" Font-Bold="True" ForeColor="White" Font-Size="X-Small"/>
<PagerStyle BackColor="#61A2B0" ForeColor="White" CssClass="gvwCasesPager pager cssPager gvPagerCss" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Font-Size="Small"/>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
as you can see in above gridview design there are three columns which has format "MM/dd/yyyy", I want to sort those propoerly, can you help me with this?