Non-invocable member cannot be used like a method

70,930

Solution 1

strTomorrow = DateTime.Today.AddDays(1).ToString("yyyyMMdd");
  • String.Format always returns a string, there's no need to convert the result to a string
  • String.Format does not accept a DateTime as its first argument. The easiest way to convert a DateTime to a string in a specific format is to call DateTime.ToString and pass the format as an argument

Solution 2

Today is a property so you shouldn't add parentheses. You also have the arguments to string.Format incorrect.

strTomorrow = String.Format("{0:yyyyMMdd}", DateTime.Today.AddDays(+1));

Solution 3

DateTime.Today is a property, not a method. Remove the parantheses.

Solution 4

Change DateTime.Today().AddDays(1) to DateTime.Today.AddDays(1)

Today is a property, not a method.

Share:
70,930
salvationishere
Author by

salvationishere

Updated on December 04, 2020

Comments

  • salvationishere
    salvationishere over 3 years

    I am trying to rewrite a VB function into C#, but I'm getting the following error:

    Error 1 Non-invocable member 'System.DateTime.Today' cannot be used like a method. C:\Documents and Settings\daultrd\Local Settings\Temp\SSIS\ST_ceaa126ff88343ccbfdc6dd27d8de1a7\ScriptMain.cs 56 67 ST_ceaa126ff88343ccbfdc6dd27d8de1a7

    And the offending line:

    strTomorrow = Convert.ToString(String.Format(DateTime.Today().AddDays(+1), "yyyyMMdd"));   
    

    How can I fix this? Thanks guys; you are super quick! And all of u said about the same thing. So I removed the parenthesis but now I get a different error:

    Error 1 The best overloaded method match for 'string.Format (System.IFormatProvider, string, params object[])' has some invalid arguments C:\Documents and Settings\daultrd\Local Settings\Temp\SSIS\2e23c9f006d64c249adb3d3a2e597591\ScriptMain.cs 56 44 st_ceaa126ff88343ccbfdc6dd27d8de1a7

    And here is this line of code:

    strTomorrow = Convert.ToString(String.Format(DateTime.Today.AddDays(+1), "yyyyMMdd"));   //Strings.Format(DateAndTime.Today().AddDays(+1), "yyyyMMdd"));
    
    • Lasse V. Karlsen
      Lasse V. Karlsen about 13 years
      Your first reaction to any such problem should always be to check the documentation.
  • salvationishere
    salvationishere about 13 years
    Error 1 The best overloaded method match for 'string.Format(System.IFormatProvider, string, params object[])' has some invalid arguments C:\Documents and Settings\daultrd\Local Settings\Temp\SSIS\2e23c9f006d64c249adb3d3a2e597591\ScriptMa‌​in.cs 56 44 st_ceaa1‌​26ff88343ccbfdc6dd27‌​d8de1a7
  • salvationishere
    salvationishere about 13 years
    Awesome! Thanks so much, Tom! You are a superstar.
  • Tom Vervoort
    Tom Vervoort about 13 years
    Not really, but I'm glad to help you out :-)