Date Issue.
I have a Column in a SQL Server Database named LeadDate as a DATETIME DataType.
The value in this column is 2005-10-06 00:00:00.000
I retrieve the value like so.
this.txtBoxMeetingLeadDate.Text = DRAccountMeeting["LeadDate"].ToString();
The problem is that in the textBox, it displays as 2005-10-06 12:00 00 AM
Why is my application displaying the time portion of 12:00 00 AM when in the Database it's 00:00 00?
[456 byte] By [
CSD] at [2007-11-19 14:07:37]

# 1 Re: Date Issue.
there is no 00:00 AM. What you can do is, pass the format string to the ToString() method to get the desired value.
The following format will display the time value in 24 hours format.
DRAccountMeeting["LeadDate"].ToString("mm/dd/yyyy HH:mm:ss");
Please check the following link for more format information
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasstostringtopic3.asp
# 2 Re: Date Issue.
Thanks for the reply. I tried what you said but i get an error of;
"No overload for method ToString takes 1 argument".
Below is the code that tried.
this.txtBoxMeetingLeadDate.Text = DRAccountMeeting["LeadDate"].ToString("mm/dd/yyyy HH:mm:ss");
In addition, I need the format to be dd/mm/yy or dd-mm-yy(Australian format)
CSD at 2007-11-9 1:53:46 >

# 3 Re: Date Issue.
what does the "DRAccountMeeting["LeadDate"]" return? If it returns object, please typecast it to datetime and try the method.
object val = DRAccountMeeting["LeadDate"];
if ((val != null) && (val is DateTime))
{
DateTime leadDate = val as DateTime;
leadDate.ToString("dd-mm-yy");
}
[updated] the "is" operator will not work with value type. Please subtitute with the correct type checking code (I couldn't think of any at this time).
# 4 Re: Date Issue.
Hmmmm...We have almost solved it! Below is the code I have. Whats happening now is the date is showing in the textBox as 06-00-05 instead of 06-10-2005.
Not sure why the month is now 00 instead of 10.
object valLeadDate = DRAccountMeeting["LeadDate"];
if ((valLeadDate != null) && (valLeadDate is DateTime))
{
DateTime leadDate = Convert.ToDateTime(valLeadDate);
//leadDate.ToString("dd-mm-yy");
this.txtBoxMeetingLeadDate.Text = leadDate.ToString("dd/mm/yy");
}
CSD at 2007-11-9 1:55:42 >
