954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to split datetime format?

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

satees
Newbie Poster
15 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
 

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)

nikkiH
Junior Poster in Training
79 posts since Dec 2006
Reputation Points: 13
Solved Threads: 4
 

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.

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

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>
showtime
Newbie Poster
3 posts since Jun 2006
Reputation Points: 10
Solved Threads: 0
 
dsa
Newbie Poster
2 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You