Results 1 to 2 of 2

Thread: [RESOLVED] Nullable datatype inhibits formatting?

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    334

    Resolved [RESOLVED] Nullable datatype inhibits formatting?

    I'm trying to format a date. This works:
    Dim x As Date = Today
    Dim y As String
    y = x.ToString("MMMM d, yyyy")

    But this doesn't:
    Dim x As Date? = Today
    Dim y As String
    y = x.ToString("MMMM d, yyyy")

    When x is nullable I get an error 'Overload resolution failed because no accessible ToString accepts this number of arguments'.

    I suppose I could copy the nullable variable into a non-nullable variable, then format it, but that seems extremely clumsy for something that should be fairly simply. Isn't there a better way?

    Thanks.

    Arghh! Copying the Date? variable into a Date variable doesn't work-Option Strict is On & that sees the two variables as being of different types. Is it really necessary to to an explicit CDate conversion on a nullable date variable?

    OK, found an example that works. Problem is I was calling ToString directly on the nullable Date? variable-what I need to do is call it on the Value of that:
    y = x.Value.ToString("MMMM d, yyyy")

    That works.
    Last edited by calvin-c; Nov 29th, 2010 at 03:00 PM. Reason: Solved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width