Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to change the date format in asp.net

Posted on 2009-06-29
2
1,723 Views
Last Modified: 2013-11-18
Hi,
I want to change date format of pubDate to dd-mm-yy.

Code is:
<body>
    <form id="form1" runat="server">
    <div>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://blogs.msdn.com/amit_chatterjee/rss.xml"
            XPath="rss/channel/item [position()<=1]" CacheDuration="60"></asp:XmlDataSource>
    </div>
        <asp:DataList  Runat="server" DataSourceID="XmlDataSource1" >
            <ItemTemplate>
                <asp:Label ID="Label1" Runat="server" Text='<%# XPath("pubDate") %>' ForeColor="black" Font-Bold="True"></asp:Label>
            </ItemTemplate>
        </asp:DataList>
    </form>
</body>

The output of above code is Sat, 13 Jun 2009 04:38:00 GMT can you help me how to convert this to 04:38 hrs, 13-06-09 .

Thanks in advance
0
Comment
Question by:Byteridge
2 Comments
 
LVL 6

Expert Comment

by:PIERCGG
ID: 24738372
As explained on this web page, you could do this:
http://forums.asp.net/t/707491.aspx



<asp:FormView ID="fmviewAccDate" runat="server" DataSourceID="sqldsReviewDetail">
<ItemTemplate>
<asp: Label ID="lblModalAccomplishDate" runat="server" Text='<%# Bind("PTRT_Accomplish_Date", "{0:dd/MM/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
</asp:FormView>
0
 
LVL 2

Accepted Solution

by:
Byteridge earned 0 total points
ID: 24791771
I found the solution is
<%# String.Format("{0:HHmm 'hrs,' dd-MM-yy}", Convert.ToDateTime(XPath("pubDate")))%>

Cheers
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question