Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

FormatDateTime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C - 16 Oct 2007 21:11 GMT
I have a web page field formatted with FormatDateTime(mydate,2) and when the
column is NULL the report shows 1/1/0001

Thanks

David
HockeyFan - 16 Oct 2007 22:28 GMT
> I have a web page field formatted with FormatDateTime(mydate,2) and when the
> column is NULL the report shows 1/1/0001
>
> Thanks
>
> David

What I would do, David, is to write a server-side function that takes
an object as input.  Pass the datefield to this function.  The
function then checks to see if the object is null.  If so, the
function should return whatever string you figure you want or even ""
so that nothing prints out for date if the date is null.
If the object isn't null, then cast it to a string and then do
whatever date formatting you need to do, and return this string.
It'll work just fine.

I've done this calling it from server side.  I've also done this
client side on other types of data.  Here's an example:

Text='<%# Cnote.CaseNoteTypeDescription( DataBinder.Eval(Container,
"DataItem.CnoteType")) %>'

   Public Function CaseNoteTypeDescription(ByVal obj As Object) As
String
       Dim strReturn As String = String.Empty
       Dim strCode As String

       If (obj Is Nothing) Then
           Return String.Empty
       End If
       strCode = obj.ToString()

       If (strCode = String.Empty) Then
           Return String.Empty
       End If

       If (pCaseNotesTypeCodes Is Nothing) Then
           pCaseNotesTypeCodes = New Hashtable
       End If

       If (pCaseNotesTypeCodes.Contains(strCode)) Then
           Return pCaseNotesTypeCodes.Item(strCode)
       End If
       Dim CnoteType As ComitData.LOOKUP_CASE_NOTE_TYPE

       Try
           CnoteType =
ComitData.LOOKUP_CASE_NOTE_TYPE.Retrieve(strCode)
       Catch ex As Exception
           AppErrorLog.Log("CaseNoteType bad", "Case note type is
note listed in the lookup table: " & strCode,
System.Environment.UserName, True)
           Return String.Empty
       End Try
       strReturn = CnoteType.Description + ""
       pCaseNotesTypeCodes.Add(strCode, strReturn)

       Return strReturn
   End Function

I've done this plenty of times.  You can call your function from
inside a gridview.  You can call it from the text property of a
textbox or a label or whatever control you want.  As you can see, by
passing the raw database field in as an object, it wont break if the
data item is null.  You can check it safely and format it according to
whatever rules you feel you want.
Good luck.
David C - 17 Oct 2007 14:52 GMT
Thanks, I'll give it a try.
>> I have a web page field formatted with FormatDateTime(mydate,2) and when
>> the
[quoted text clipped - 64 lines]
> whatever rules you feel you want.
> Good luck.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.