Solved

Format Datetime without seconds on GridView

Posted on 2008-09-29
6
1,394 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
  • 3
  • 3
6 Comments
 
LVL 2

Expert Comment

by:nenwmn
Comment Utility
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
Comment Utility
Restrict the length of the format string.
0
 

Author Comment

by:GravitaZ24
Comment Utility
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
Comment Utility
{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
Comment Utility
oh ya, thank you! that worked well, is there a way to still have the AM/PM in it?
0
 

Author Comment

by:GravitaZ24
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

772 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

12 Experts available now in Live!

Get 1:1 Help Now