70

I'm trying to populate an expression (default value of a parameter) with an explicit time. How do I remove the time from the the "now" function?

Pedram
  • 6,256
  • 10
  • 65
  • 87
Jeff
  • 8,020
  • 34
  • 99
  • 157
  • 1
    Check out Method 1: http://stackoverflow.com/a/19693553/2635532 – Anup Agrawal Feb 05 '16 at 17:17
  • 2
    It is important to note that even if the SQL within returns a Date variable only, the rdl will still use DateTime. Therefore, it must be formatted by the rdl -- see various answers below. – JosephDoggie Jan 15 '20 at 14:08

14 Answers14

110

Something like this:

=FormatDateTime(Now, DateFormat.ShortDate) 

Where "Now" can be replaced by the name of the date/time field that you're trying to convert.)
For instance,

=FormatDateTime(Fields!StartDate.Value, DateFormat.ShortDate)
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Michael Maddox
  • 12,331
  • 5
  • 38
  • 40
  • 6
    As my date parameter was a datetime, I required an additional CDate() around the above expression. – Nick.Mc Mar 13 '14 at 01:51
  • 1
    Won't work if the report is required in Excel format. FormatDateTIme is string function. Sure it strips off the time, but the result is a string date column which when sorting will be sorted as a string from left to right. The user would have to convert the column to a real Date using Text to Columns. – Fandango68 Jun 21 '16 at 00:17
  • 1
    The point is, you cannot do what the OP asked in Date only format. You're stuck with string dates. – Fandango68 Jun 21 '16 at 00:20
  • This gave me exactly what I needed. I had a DOB column that SSRS assumed needed to add a time to. Microsoft really needs to update this software. –  Jan 28 '21 at 17:23
46

Since SSRS utilizes VB, you can do the following:

=Today() 'returns date only

If you were to use:

=Now() 'returns date and current timestamp
RSolberg
  • 26,821
  • 23
  • 116
  • 160
29
=CDate(Now).ToString("dd/MM/yyyy")

Although you are hardcoding the date formart to a locale.

Pedram
  • 6,256
  • 10
  • 65
  • 87
Perhentian
  • 860
  • 8
  • 12
23

If you have to display the field on report header then try this... RightClick on Textbox > Properties > Category > date > select *Format (Note this will maintain the regional settings).

Since this question has been viewed many times, I'm posting it... Hope it helps.

enter image description here

singhswat
  • 832
  • 7
  • 20
  • 1
    What if it gets ignored for whatever reason? E.g. date is still shown with hours and minutes. Any idea why this could be happening? – Alex Mar 03 '16 at 10:43
  • 2
    If you have a function specified for the value of the TextBox/Placeholder then it will override the formatting options on this screen. – Wayne May 31 '16 at 20:04
  • 1
    Saved my day. Event though it is easily visible in the options many wont look here for formatting option. Thanks a lot. – Rohith Jan 30 '18 at 09:03
8

Just use DateValue(Now) if you want the result to be of DateTime data type.

antyrat
  • 27,479
  • 9
  • 75
  • 76
user1165019
  • 93
  • 2
  • 5
8

If expected data format is MM-dd-yyyy then try below,

=CDate(Now).ToString("MM-dd-yyyy")

Similarly you can try this one,

=Format(Today(),"MM-dd-yyyy") 

Output: 02-04-2016

Note:
Now() will show you current date and time stamp

Today() will show you Date only not time part.

Also you can set any date format instead of MM-dd-yyyy in my example.

Pedram
  • 6,256
  • 10
  • 65
  • 87
5

In the format property of any textbox field you can use format strings:

e.g. D/M/Y, D, etc.

zzawaideh
  • 2,021
  • 1
  • 17
  • 25
  • 4
    The question is referring to the default value of a report parameter, so setting the format on a textbox won't work. Also, "D/M/Y" won't give the expected result, try "dd/MM/yyyy" instead. – Valentino Vranken Jul 31 '12 at 08:24
3

One thing that might help others is that you can place: =CDate(Now).ToString("dd/MM/yyyy") in the Format String Property of SSRS which can be obtained by right clicking the column. That is the cleanest way to do it. Then your expression won't be too large and difficult to visually "parse" :)

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
lbranjord
  • 31
  • 1
2

Found the solution from here

This gets the last second of the previous day:

DateAdd("s",-1,DateAdd("d",1,Today())

This returns the last second of the previous week:

=dateadd("d", -Weekday(Now), (DateAdd("s",-1,DateAdd("d",1,Today()))))
Pedram
  • 6,256
  • 10
  • 65
  • 87
Jeff
  • 8,020
  • 34
  • 99
  • 157
  • 7
    I stumbled here from google.. but.. this doesn't answer your question. (why do you care about the last second?) However, you did beat RSolberg (who correctly answered it). Maybe you should edit your accepted answer to reference his correct answer? – itchi Aug 26 '10 at 00:29
  • 3
    DateAdd("s",-1,DateAdd("d",1,Today()) returns the last second of Today, not previous day - and there's a closing backet missing to make it work – Valentino Vranken Jul 31 '12 at 08:20
2
    FormatDateTime(Parameter.StartDate.Value)
Alivia
  • 1,312
  • 1
  • 10
  • 17
2

I'm coming late in the game but I tried all of the solutions above! couldn't get it to drop the zero's in the parameter and give me a default (it ignored the formatting or appeared blank). I was using SSRS 2005 so was struggling with its clunky / buggy issues.

My workaround was to add a column to the custom [DimDate] table in my database that I was pulling dates from. I added a column that was a string representation in the desired format of the [date] column. I then created 2 new Datasets in SSRS that pulled in the following queries for 2 defaults for my 'To' & 'From' date defaults -

'from'

    SELECT  Datestring
    FROM    dbo.dimDate
    WHERE   [date] = ( SELECT   MAX(date)
                       FROM     dbo.dimdate
                       WHERE    date < DATEADD(month, -3, GETDATE()
                     )

'to'

    SELECT  Datestring
    FROM    dbo.dimDate
    WHERE   [date] = ( SELECT   MAX(date)
                       FROM     dbo.dimdate
                       WHERE    date <= GETDATE()
                     )
Chris Wood
  • 535
  • 9
  • 28
2

This should be done in the dataset. You could do this

Select CAST(CAST(YourDateTime as date) AS Varchar(11)) as DateColumnName

In SSRS Layout, just do this =Fields!DateColumnName.Value

Pedram
  • 6,256
  • 10
  • 65
  • 87
Ricky Hope
  • 51
  • 1
  • 5
  • Won't strip off the time component is the DateColumnName is a DateTime datatype. The OP wants the date only. – Fandango68 Jun 21 '16 at 00:13
2

My solution for a Date/Time parameter:

=CDate(Today())

The trick is to convert back to a DateTime as recommend Perhentian.

will webster
  • 574
  • 5
  • 11
2

Just concatenate a string to the end of the value:

Fields!<your field>.Value & " " 'test' 

and this should work!

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
amad
  • 59
  • 1
  • 4
  • 1
    Hi Nathan, Would you please elaborate on your editing ?. sorry i am kind of new to stackoverflow. Regards! – amad Jul 14 '17 at 15:33