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.


Recommended Answers

All 5 Replies

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.

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.

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">
                                                                        <td valign="top" width="110px">
                                                                            <img border="0" src="images/<%# Eval("strLogo")%>" />
                                                                        <td valign="top" class="bluebodytext">
                                                                            <%# Eval("txtDescription")%>
                                                                            <i>Offer Expires
                                                                                <%# String.Format("{0:d}",Eval("dtmExpiration")) %>
                                                                <div class="row">

This post is 11 months old.. why bring it up unless you have a question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.