Forum Moderators: open

Message Too Old, No Replies

date/time

         

hal12b

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

10+ Year Member



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

mattglet

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

WebmasterWorld Senior Member 10+ Year Member



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.

hal12b

1:45 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



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.

hal12b

1:47 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



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

Ocean10000

2:52 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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

References:
DateTime.ToString Method (String) [msdn.microsoft.com]

hal12b

3:44 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



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:

Ocean10000

3:59 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Convert.ToDateTime(Utils.CheckForNull_Text2(Container.DataItem("DATE_SUBMITTED"))).toString("MM/dd/yyyy")

hal12b

4:06 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



Nice! It works.