Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format Datetime without seconds on GridView

Posted on 2008-09-29
6
Medium Priority
?
1,493 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

609 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