Welcome to WebmasterWorld Guest from 35.153.73.72

Forum Moderators: ocean10000

Message Too Old, No Replies

date/time

     
9:37 pm on Feb 16, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


If I am storing a date in a database and it looks like this when outputted on my page -->
<%# Utils.CheckForNull_Text2(Container.DataItem("DATE_SUBMITTED"))%>

produces -->

2/16/2011 4:16:44 PM



How can I strip off the "4:16:44 PM" I only want to display the date.


Thanks
10:58 pm on Feb 16, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


You can use Convert.ToDateTime(YOUR DATE HERE).ToShortDateString()

I can't apply it to your code because if you have the possibility to return a null value, that will fail. You would first need to ensure that you're not passing null/empty string to the Convert function.
1:45 pm on Feb 17, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


OK thanks. I will try it out. It will never be null though. I am time stamping each entry into the database. Appreciate the prompt assistance.
1:47 pm on Feb 17, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


One other question. I'd like these to line up better so instead of

2/9/2011
2/16/2011
2/17/2011
12/17/2011

I'd like

02/09/2011
02/16/2011
02/17/2011
12/17/2011

How can I do this?
Thanks
2:52 pm on Feb 17, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Convert.ToDateTime(YOUR DATE HERE).toString("MM/dd/yyyy")

References:
DateTime.ToString Method (String) [msdn.microsoft.com]
3:44 pm on Feb 17, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


Any suggestions?
having problems

The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.

Source Error:

Line 99:
Line 100:
Line 101:<%# Utils.CheckForNull_Text2(Container.DataItem(Convert.ToDateTime("DATE_SUBMITTED").toString("MM/dd/yyyy") ))%>
Line 102:
Line 103:
3:59 pm on Feb 17, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Convert.ToDateTime(Utils.CheckForNull_Text2(Container.DataItem("DATE_SUBMITTED"))).toString("MM/dd/yyyy")
4:06 pm on Feb 17, 2011 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 24, 2005
posts:429
votes: 0


Nice! It works.