0

I'm using the following in my grid view to display two dates in a single column. How can I change this so the date format will be like dd MMM yyyy without the time?

<asp:TemplateField HeaderText="Date Range">
    <ItemTemplate>
        <%# string.Format("{0} {1}", Eval("From_Date ") ,Eval("To_Date"))%>
    </ItemTemplate>
</asp:TemplateField>

1 Answer 1

0

It should be a matter of adding :dd MMM yyyy after 0, resp 1

Like:

<asp:TemplateField HeaderText="Date Range">
    <ItemTemplate>
        <%# string.Format("{0:dd MMM yyyy} {1:dd MMM yyyy}", Eval("From_Date") ,Eval("To_Date"))%>
    </ItemTemplate>
</asp:TemplateField>
2
  • Thanks Robert - that works perfectly. Any Idea how I might be able to hide the second date when it is the same as the first date? I'm posting a new question about this anyway, but maybe you know how... Commented Nov 15, 2013 at 7:32
  • I have given it a shot! not sure it is corret though as I can't compile it right now Commented Nov 15, 2013 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.