943,972 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 32788
  • ASP.NET RSS
Dec 29th, 2006
0

How to split datetime format?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
satees is offline Offline
15 posts
since Nov 2006
Dec 29th, 2006
0

Re: How to split datetime format?

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.
Reputation Points: 13
Solved Threads: 4
Junior Poster in Training
nikkiH is offline Offline
79 posts
since Dec 2006
Dec 30th, 2006
0

Re: How to split datetime format?

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.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Jan 3rd, 2007
0

Re: How to split datetime format?

If its in a gridview, something like this works
ASP.NET Syntax (Toggle Plain Text)
  1. <%# String.Format("{0:d}",Eval("dtmExpiration")) %>
The whole grdiview might look something like this
ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
showtime is offline Offline
3 posts
since Jun 2006
Nov 7th, 2007
0

Re: How to split datetime format?

dsa
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dsa is offline Offline
2 posts
since Nov 2007
Nov 7th, 2007
0

Re: How to split datetime format?

This post is 11 months old.. why bring it up unless you have a question?
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: background-color:"9E0039" works in IE but not mozilla, solution?
Next Thread in ASP.NET Forum Timeline: Content Changes across pages via Drop-Down Box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC