How to split datetime format?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 15
Reputation: satees is an unknown quantity at this point 
Solved Threads: 0
satees satees is offline Offline
Newbie Poster

How to split datetime format?

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: How to split datetime format?

 
0
  #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 9: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 Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 26
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: How to split datetime format?

 
0
  #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 3:27 pm.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 3
Reputation: showtime is an unknown quantity at this point 
Solved Threads: 0
showtime showtime is offline Offline
Newbie Poster

Re: How to split datetime format?

 
0
  #4
Jan 3rd, 2007
If its in a gridview, something like this works
  1. <%# String.Format("{0:d}",Eval("dtmExpiration")) %>
The whole grdiview might look something like this
  1. <asp:GridView Width="100%" BorderWidth="0" CellPadding="0" CellSpacing="0" BorderColor="white"
  2. AutoGenerateColumns="FALSE" ShowHeader="false" ID="gvStores" runat="server">
  3. <Columns>
  4. <asp:TemplateField>
  5. <ItemTemplate>
  6. <table>
  7. <tr>
  8. <td valign="top" width="110px">
  9. <img border="0" src="images/<%# Eval("strLogo")%>" />
  10. </td>
  11. <td valign="top" class="bluebodytext">
  12. <%# Eval("txtDescription")%>
  13. <i>Offer Expires
  14. <%# String.Format("{0:d}",Eval("dtmExpiration")) %>
  15. </i>
  16. </td>
  17. </tr>
  18. </table>
  19. <div class="row">
  20. &nbsp;
  21. </div>
  22. </ItemTemplate>
  23. </asp:TemplateField>
  24. </Columns>
  25. </asp:GridView>
Last edited by Paladine; Jan 4th, 2007 at 8:17 pm. Reason: Adding Code Blocks
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1
Reputation: dsa is an unknown quantity at this point 
Solved Threads: 0
dsa dsa is offline Offline
Newbie Poster

Re: How to split datetime format?

 
0
  #5
Nov 7th, 2007
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: How to split datetime format?

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

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC