?
Solved

Format Datetime without seconds on GridView

Posted on 2008-09-29
6
Medium Priority
?
1,478 Views
Last Modified: 2012-05-05
One of my Gridview columns contains a datetime value that I would like formatted without seconds.  For example, a meeting is currently being displayed as 11/2/2006 6:30:00 PM.  I would like to have it displayed as /2/2006 6:30 PM.

After some research, I thought I had the answer by using DataFormatString as follows:

<
asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy HH:mm}" />

But I am still getting the seconds displayed.  How can I eliminate the seconds in the Date column of my Gridview?  Thanks for any help provided.
0
Comment
Question by:GravitaZ24
[X]
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
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:nenwmn
ID: 22595923
The DataFormatString {0:MM/dd/yyyy} should work the example you show still has the hours an miniutes.
Regards, Neil
0
 
LVL 2

Expert Comment

by:nenwmn
ID: 22596006
Restrict the length of the format string.
0
 

Author Comment

by:GravitaZ24
ID: 22596057
how exactly would I do that, and to respond your first answer, the only thing I'm looking to get rid of is the seconds.
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 2

Accepted Solution

by:
nenwmn earned 1000 total points
ID: 22597433
{0:MM/dd/yyyy HH:mm} works when tested on a bound datasource, do you get the same result using an item template label control. <asp:label id="datelabel" Text='<%# Bind("Date", "{0:MM/dd/yyyy HH:mm}") %>'</asp:label>.
Regards, Neil
 
0
 

Author Comment

by:GravitaZ24
ID: 22597817
oh ya, thank you! that worked well, is there a way to still have the AM/PM in it?
0
 

Author Comment

by:GravitaZ24
ID: 22598543
NM, thanks for all the help, i found this really helpful site for anyone else who has this question
http://authors.aspalliance.com/aspxtreme/sys/demos/datetimeformats.aspx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

752 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