Hi,

I have stored "DateTime" format in the database, but i need only "date" at the time of retrive. How to do this? Please help.

Thanks in advance.

Satees

You have a datetime. How you display it is up to you. The DateTime object supports multiple methods for displaying the date, as well as an overridden ToString that can take a format.
http://msdn2.microsoft.com/en-us/library/system.datetime_methods.aspx

If for some reason you want it returned from the database as a string that is already formatted, the question is more relevant in an SQL forum, since it then becomes database dependent. SQL Server supports the convert function for dates, i.e.
convert(varchar,mydatefield,101)

Good points nikkiH!

One thing that can be done as well is to retrieve the date/time from the database as stored and use the parse/format methods in ASP.NET to produce the desired output.


Satees - the links nikkiH provide is an excellent starting point.

If its in a gridview, something like this works

<%# String.Format("{0:d}",Eval("dtmExpiration")) %>

The whole grdiview might look something like this

<asp:GridView Width="100%" BorderWidth="0" CellPadding="0" CellSpacing="0" BorderColor="white"
                                                    AutoGenerateColumns="FALSE" ShowHeader="false" ID="gvStores" runat="server">
                                                    <Columns>
                                                        <asp:TemplateField>
                                                            <ItemTemplate>
                                                                <table>
                                                                    <tr>
                                                                        <td valign="top" width="110px">
                                                                            <img border="0" src="images/<%# Eval("strLogo")%>" />
                                                                        </td>
                                                                        <td valign="top" class="bluebodytext">
                                                                            <%# Eval("txtDescription")%>
                                                                            <i>Offer Expires
                                                                                <%# String.Format("{0:d}",Eval("dtmExpiration")) %>
                                                                            </i>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                                <div class="row">
                                                                    &nbsp;
                                                                </div>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
This article has been dead for over six months. Start a new discussion instead.