0

right now i want to make the date to appear like this dd/mm/yyyy in my front end (as in after debug). but it is appearing like this mm/dd/yyyy. but after i execute the stored procedure in sql server it is the result that i wanted.

this is my code.

       <div class="content-frame-bottom type4" style="overflow-x:auto;">    
                    <table width="100%" class="table table-bordered table-condensed">        
                    <asp:Repeater ID="rptReport" runat="server" onitemcommand="rptReport_ItemCommand" >
                        <HeaderTemplate>
                          <tr>
                          <td width="8%" class="table-header2">Date</td>
                          </tr>
                          </HeaderTemplate>

                          <ItemTemplate>
                          <tr>
                            <td><%#  Eval("Date") %> </td>
                          </tr>
                         </ItemTemplate>
                          </asp:Repeater>
                          </div>

this is my code in aspx page. how do i make the date to appear in dd/mm/yyyy format. where should i insert it. thanks for helping.

SKJ
  • 37
  • 1
  • 10
  • just this within td `Convert.ToDateTime(Eval("Date")).ToString("dd/MM/yyyy")` – Suprabhat Biswal Jan 09 '15 at 06:00
  • i tried adding it in the item template but it is not working. it tells me that "Operator '/' cannot be applied to operands of type 'string' and 'string'". @Suprabhat – SKJ Jan 09 '15 at 06:52
  • don't know what you have tried but i have simply replaced your `<%# Eval("Date") %>` with mine `<%# Convert.ToDateTime(Eval("Date")).ToString("dd/MM/yyyy") %>` and it's perfectly working for me in my dummy application. – Suprabhat Biswal Jan 09 '15 at 08:05

4 Answers4

2

Try this to convert date to dd/mm/yyyy format

<%#Eval("Date", "{0:dd/MM/yyyy}")%>
0

do something like this in server side

 string yourdate="01/23/2014";

DateTime timezz = DateTime.Parse(yourdate);
      yourdate = timezz.ToString("dd/MM/yyyy");

then dynamically add date value to your table

if u want to do it directly in client side then you can use javascript or,String.format Function

or else if you are downloading moment.js source then simply you can do what ever you want Example :

<script>
$(document).ready(function() {

     $("#date").val( moment().format('MMM D, YYYY') );

});
</script>

Reference :

Community
  • 1
  • 1
Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
0

You can try this:

<%# DataBinder.Eval(Container.DataItem, "Date", "{0:dd/MM/yyyy}") %>

Or

<%# string.Format("{0:dd/MM/yyyy}", Eval("Date"))%>
Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
0

you can try this. This may work.

Eval("Date").ToString("dd'/'MM'/'yyyy");
vishu9219
  • 761
  • 6
  • 14
  • Operator '/' cannot be applied to operands of type 'string' and 'string'. @vishu9219 – SKJ Jan 09 '15 at 06:41
  • because your date is already in string format , if it is in date format then only the above code is working.change it first as date format then use above code it will work – Arunprasanth K V Jan 09 '15 at 08:08