ASP.NET gridview boundfield datetime format

Posted on 2007-10-03
Last Modified: 2012-06-21
Given a sqlserver datetime field
2007-10-03 20:53:25.373
how can it be formatted in a gridview boundfield as:
 "10/03/2007 20:53:25"
and not "10/03/2007 8:53:25 PM"?
Question by:ksfok
    LVL 12

    Accepted Solution

    in the dataformatstring of the boundfield use  {0:MM/dd/yyyy HH:mm:ss}
    LVL 16

    Assisted Solution

    Note that you must also set the "HtmlEncode" attribute to "false" for formatting to work correctly with bound fields and dates.
    LVL 12

    Expert Comment

    also set the HtmlEncode property on the boundfield to false.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now