Solved

Format Datetime without seconds on GridView

Posted on 2008-09-29
6
1,437 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 2

Accepted Solution

by:
nenwmn earned 250 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

726 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