SmartDate Format Issue...

SmartDate Format Issue...

Old forum URL: forums.lhotka.net/forums/t/2998.aspx


reagan123 posted on Thursday, June 07, 2007

Hi everyone.

Currently my SmartDates are being formatted using the following in the FormatString() method in the smartdate class.

mFormat = "G"

This works great and displays my date's in the following manner.

4/14/2005 12:00:00 A.M.

The issue is, there is one smatdate that I want to just display as a shortdate.  How can I format this on instance of smartdate as the shortdate?

Any help greatly appreciated.

VisualStudio2005 Windows Project
CSLA Ver.2

reagan123 replied on Thursday, June 07, 2007

By the way.. figured I'd add some detail...  here is the property I use

Public ReadOnly Property LastInspectionDate() As SmartDate
Get
      
Return _lastInspectionDate
End Get
End Property

I've tried the following line of code, but I get the following error of course. 

return _lastInspectionDate.Date.ToString("MM/dd/yyyy");

Value of type 'String' cannot be converted to SmartDate

McManus replied on Thursday, June 07, 2007

Hi reagan123,

The SmartDate class uses the date format "d" as default. You can call the shared method SetDefaultFormatString("G") on the SmartDate class. After that, you can use the Text property of the SmartDate instance to get the string representation of the date.

For your _lastInspectionDate property, you should set the FormatString property of the instance to "MM/dd/yyyy". (you can do that immediately after you've created the object) After that, the Text property should return the date in the desired format.

Hope this helps,

Cheers,

Herman

Brian Criswell replied on Thursday, June 07, 2007

A lot of people expose their SmartDates as strings (as the examples in Rocky's book show).  You could then use the formattable ToString() but setting the format string is more correct.

reagan123 replied on Friday, June 08, 2007

thanks again guys... It works great now.


I believe this forum is 3 for 3 know on my questions  Big Smile [:D]

Copyright (c) Marimer LLC