User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,908 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,624 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 9602 | Replies: 5
Reply
Join Date: Nov 2006
Posts: 15
Reputation: satees is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
satees satees is offline Offline
Newbie Poster

How to split datetime format?

  #1  
Dec 29th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: Near Chicago
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: How to split datetime format?

  #2  
Dec 29th, 2006
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/lib...e_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)
Last edited by nikkiH : Dec 29th, 2006 at 8:56 am.
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 26
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: How to split datetime format?

  #3  
Dec 30th, 2006
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.
Last edited by Paladine : Dec 30th, 2006 at 2:27 pm.
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Join Date: Jun 2006
Posts: 3
Reputation: showtime is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
showtime showtime is offline Offline
Newbie Poster

Re: How to split datetime format?

  #4  
Jan 3rd, 2007
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>
Last edited by Paladine : Jan 4th, 2007 at 7:17 pm. Reason: Adding Code Blocks
Reply With Quote  
Join Date: Nov 2007
Posts: 1
Reputation: dsa is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dsa dsa is offline Offline
Newbie Poster

Re: How to split datetime format?

  #5  
Nov 7th, 2007
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: How to split datetime format?

  #6  
Nov 7th, 2007
This post is 11 months old.. why bring it up unless you have a question?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 7:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC