11

I have a report in my application and this report will show a long date from db and I used this expression to make it shorter:

=FormatDateTime(Fields!StatementDate.Value,DateFormat.ShortDate)

and the date will show like this : 1/1/2010

I need to make it like this : 2010/1/1

How I can do it?

Saleh
  • 2,657
  • 12
  • 46
  • 73

3 Answers3

24

That expression do the trick

=CDate(Fields!Fecha.Value).ToString("yyyy/M/d")
pcofre
  • 3,976
  • 18
  • 27
9

I think that it is a lot cleaner to use the Format property rather than format it in your expressions: http://msdn.microsoft.com/en-us/library/ms252080%28v=vs.90%29.aspx

You can use the standard .NET formatting strings.

Value=Fields!StatementDate.Value
Format=yyyy/M/d

Fields!StatementDate.Value will need to be a DateTime, if not you can try convert it:

Value=CDate(Fields!StatementDate.Value)
row1
  • 5,568
  • 3
  • 46
  • 72
  • 1
    thank you it's better approach because one can handle null value with it – ghazyy Oct 02 '13 at 08:44
  • Agreed, however in my report, I have a "Payroll Period" that I need to format `FromDate - ToDate`. So for the purposes of the search that brought me to this question, @pcofre's answer did the trick. Normally, when I want to apply a custom format to a single date column, I would definitely use your approach. – Bob Kaufman Jan 15 '20 at 16:07
1
=CDate(Fields!StatementDate.Value).ToShortDateString()
Irshad
  • 3,071
  • 5
  • 30
  • 51
Arushi
  • 11
  • 1