Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Express DateTime format

Status
Not open for further replies.

CoolMama

Programmer
Jan 19, 2006
50
0
0
US
I'm using SQL Server 2005 Express and Visual Web Developer Express (ASP.NET 2.0). I've
created an ASPX page which displays policy information. The date, which has a
"datetime" property, displays with both date and time. I want only a short
date. I'm not familiar with the SQL language yet.

In the ASPX page I wrote

Code:
<asp:BoundField DataField="LastUpdated" HeaderText="Date Last Updated" 
SortExpression="LastUpdated" DataFormatString="{0:d}">

to format it. But the time portion is still there. I read something about
DATEPART, but it was too confusing to know if it was something I should be
using. Help!


Dawn
 
Here's my gridview code. How do I set that encode property you're talking about?

Code:
<asp:GridView ID="dgPolicies" runat="server" AllowSorting="True" AutoGenerateColumns="False" BorderWidth="0px" DataKeyNames="PolicyID" DataSourceID="OFpolicies" Width="600px" CssClass="accentText" CellPadding="4">
                    <HeaderStyle BackColor="SteelBlue" CssClass="accentTextWhiteBold" horizontalalign="Left" forecolor="White" verticalalign="Bottom" />
            <Columns>
                <asp:BoundField DataField="PageNumber" HeaderText="Page No." SortExpression="PageNumber" >
                    <HeaderStyle Width="15%" />
                </asp:BoundField>
                <asp:HyperLinkField DataNavigateUrlFields="Link" DataTextField="Title" HeaderText="Policy Title" SortExpression="Title">
                    <HeaderStyle Width="50%" />
                </asp:HyperLinkField>
                <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" >
                    <HeaderStyle Width="15%" />
                </asp:BoundField>
                <asp:BoundField DataField="LastUpdated" HeaderText="Date Last Updated" SortExpression="LastUpdated" DataFormatString="{0:d}">
                    <HeaderStyle Width="20%" />
                </asp:BoundField>
            </Columns>
        </asp:GridView>

Dawn
 
When the HtmlEncode property is true, the value of the field is HTML encoded to its string representation before the formatting string is applied. For some objects, such as dates, you might want to control how the object is displayed with a formatting string. In those cases, you must set the HtmlEncode property to false.
The above is taken from which shows how to use the BoundField and it's methods so you can set the suggested attribute there.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
You can change the properties of the column in the grid from the designer, click on the smart tag.
 
Thank you! It worked.

I asked this same question to the people at the link you sent me to before, but they never responded to me. Guess they're too busy. [bigcheeks]

Dawn
 
Glad it's working for you. I struggled with it myself when I first started using 2.0. Very frustrating.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top