5

Possible Duplicate:
How can I format a nullable DateTime with ToString()?
‘No overload for method 'ToString’ takes ‘1’ arguments' error occur While Formating Datetime Field To String ON “dd-MM-yyyy” format

I am using the following:

@Model.Modified.ToString("dd/MM/yyyy htt")

But it gives me a message saying

No overload method for ToString takes one argument

Does anyone have any idea what could be wrong?

Community
  • 1
  • 1
  • 2
    What is the type of `@Model.Modified`? – Douglas Dec 01 '12 at 01:19
  • DateTime? - I tried the following: ((DateTime)Model.Modified).ToString("dd/MM/yyyy htt") This worked. Do you think it's because it's DateTime? and not DateTime ?? –  Dec 01 '12 at 01:37

1 Answers1

16

Modified property on the model may not be of the type DateTime. Try casting it to DateTime before calling ToString on it.

Update based on the comment

then all you have to do is

  @Model.Modified.Value.ToString("dd/MM/yyyy htt") 

because the property is nullable

Yogiraj
  • 1,952
  • 17
  • 29
  • The property is DateTime? Would the fact it's nullable be the problem? –  Dec 01 '12 at 01:36
  • That could be it, see: http://stackoverflow.com/questions/1833054/how-can-i-format-a-nullable-datetime-with-tostring – jcolebrand Dec 01 '12 at 01:38