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?

2
  • 1
    Check out Method 1: stackoverflow.com/a/19693553/2635532 Feb 5, 2016 at 17:17
  • 2
    It is important to note that even if the SQL within <CommandText> returns a Date variable only, the rdl will still use DateTime. Therefore, it must be formatted by the rdl -- see various answers below. Jan 15, 2020 at 14:08

14 Answers 14

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)
4
  • 6
    As my date parameter was a datetime, I required an additional CDate() around the above expression.
    – Nick.Mc
    Mar 13, 2014 at 1: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, 2016 at 0: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, 2016 at 0: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.
    – user12217470
    Jan 28, 2021 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
2
  • 9
    =Today() does not return date only in SSRS
    – donviti
    Jul 29, 2014 at 16:00
  • 1
    To clarify, Today() returns the date only in terms of value, but the datatype returned is DateTime.
    – Chris Mack
    Nov 14, 2018 at 16:00
29
=CDate(Now).ToString("dd/MM/yyyy")

Although you are hardcoding the date formart to a locale.

2
  • 2
    +1 for the concise answer that, as a matter of fact, was very helpful to me.
    – jasonco
    Jan 20, 2010 at 10:52
  • 1
    As I mentioned above, this works but turns the column into a string. It's still not a true DATE only datatype.
    – Fandango68
    Jun 21, 2016 at 0:19
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

3
  • 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 3, 2016 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, 2016 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, 2018 at 9:03
9

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.

8

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

5

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

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

1
  • 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. Jul 31, 2012 at 8: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" :)

0
2
    FormatDateTime(Parameter.StartDate.Value)
1
  • 1
    You are missing the second parameter of the expression FormatDateTime(DateField, DateFormat)
    – ShellNinja
    Jan 23, 2014 at 13:31
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()
                     )
2

My solution for a Date/Time parameter:

=CDate(Today())

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

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()))))
2
  • 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, 2010 at 0: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 Jul 31, 2012 at 8:20
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

1
  • Won't strip off the time component is the DateColumnName is a DateTime datatype. The OP wants the date only.
    – Fandango68
    Jun 21, 2016 at 0:13
2

Just concatenate a string to the end of the value:

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

and this should work!

1
  • 1
    Hi Nathan, Would you please elaborate on your editing ?. sorry i am kind of new to stackoverflow. Regards!
    – amad
    Jul 14, 2017 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.