151

on SSRS report I need to show todays date and current time

i tried this =FormatDateTime(Now,"MM/dd/yyyy hh:mm tt") but this is not working for me giving an error.

Anyone please help me for expression ?

I want output display like 4/12/2013 12:05 PM

Neo
  • 15,491
  • 59
  • 215
  • 405

11 Answers11

275
=Format(Now(), "MM/dd/yyyy hh:mm tt")

Output:

04/12/2013 05:09 PM

Full list of format options might be found here. Kudos to @MattGibson.

Heavy JS
  • 51
  • 7
Ian Preston
  • 38,816
  • 8
  • 95
  • 92
  • 12
    Possible `Format()` strings are described in this article: [Date and Time Format Strings](https://msdn.microsoft.com/en-us/library/97x6twsz.aspx); I figured I'd mention that as it was what I was looking for when I arrived here! – Matt Gibson Jan 20 '16 at 10:05
22

If the date and time is in its own cell (aka textbox), then you should look at applying the format to the entire textbox. This will create cleaner exports to other formats; in particular, the value will export as a datetime value to Excel instead of a string.

Use the properties pane or dialog to set the format for the textbox to "MM/dd/yyyy hh:mm tt"

I would only use Ian's answer if the datetime is being concatenated with another string.

Jamie F
  • 23,189
  • 5
  • 61
  • 77
  • 4
    Little addon for people that may find this answer: You set the format to `="MM/dd/yyyy hh:mm tt"`. If you forget the `=`, every cell will just have `"MM/dd/yyyy hh:mm tt"` as text. – user1261104 Sep 08 '16 at 08:42
8

Hope this helps:

SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM

SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy – 10/02/2008                  

SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd – 2008.10.02           

SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy

SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy

SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy

SELECT convert(varchar, getdate(), 106) -- dd mon yyyy

SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy

SELECT convert(varchar, getdate(), 108) -- hh:mm:ss

SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)

SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy

SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd

SELECT convert(varchar, getdate(), 112) -- yyyymmdd

SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm

SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • Formatting should never be done in the datbase. It creates all kind of problems (sorting, filtering etc.) It should only be done on the presentation layer (in this case, in the report). This solution is not recommended. – swissmawi Dec 12 '22 at 08:58
7

I am using following in SSRS 2005

=Format(Globals!ExecutionTime,"MM-dd-yyyy" & " ") 
& CStr(Hour(Globals!ExecutionTime))  & ":"
& CStr(Minute(Globals!ExecutionTime))

Or

=Format(Globals!ExecutionTime,"MM-dd-yyyy" & " ") 
& Right("00" & CStr(Hour(Globals!ExecutionTime)), 2)
& ":"
& Right("00" & CStr(Minute(Globals!ExecutionTime)), 2)

OR:

=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy hh:mm.ss") 

OR

=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy HH:mm.ss")
LCJ
  • 22,196
  • 67
  • 260
  • 418
  • 4
    Both can look simpler: `=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy hh:mm.ss")` or `=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy HH:mm.ss")` – desperate man Dec 30 '14 at 14:10
6

In SSRS 2016 There is an option under the properties header "Localization" called "Calendar", if you click on this it gives you these 2 options:

  • Gregorian (dd/mm/yyyy)
  • GregorianUSEnglish (MM/dd/yyyy)

This works brilliantly when referencing data from a tables aswell

alternatively if this does not work for you, specify one of these formats under "Number" and in the cell "Format":

dd/MM/yyyy or MM/dd/yyyy

printscreen

kkuilla
  • 2,226
  • 3
  • 34
  • 37
Crezzer7
  • 2,265
  • 6
  • 32
  • 63
2

The following is how I do it using Visual Studio 2017 for an RDL targetted for SSRS 2017:

Right-click on the field in the textbox on the design surface and choose Placeholder Properties. Choose the Number panel and click on Date in the Category listbox, then select the formatting you are looking for in the Type listbox.

Del Lee
  • 442
  • 1
  • 6
  • 20
1

If you click on the empty spot on the report away from any table and then look in properties, one of the Misc fields is called Language which allows you to pick which Language you would like to set, which after doing so can play around with this

=FormatDateTime(now,x)

Which x can be 1, 2, 3, 4, 5

Tariq Khalaf
  • 89
  • 1
  • 1
  • 10
1

If you want date and time separate then use below expressions: Date and Time Expression

Expression1 for current date : =formatdatetime(today) its return date is = 11/15/2016

Expression2 for current time : =CDate(Now).ToString("hh:mm tt") its return time is = 3:44 PM

This report printed on Expression1 at Expression2

Output will be : Output of Both Expression

This report printed on 11/15/2016 at 3:44 PM

Laxman Gite
  • 2,248
  • 2
  • 15
  • 23
  • Thanks, I tried using Expression2, but it's showing 03:44 PM. Is there a way to make it show 3:44 PM and drop the leading 0? – Helen Neely Jul 06 '22 at 14:42
1
=Replace(Format(CDate(Now()),"MM.dd.yyyy"), ".", "/")
Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48
Ronney
  • 11
  • 1
1

First go to your control panel , select Date , time and Number Format . Now select English(United Kingdom) from the drop down list.

Make sure the shor date field is equal to 'dd/mm/yyyy'. Press Apply. Now go to SSRS and right click on the report in the empty space and select properties.

If you are using visual studio then set Language property equal to =User!Language.

If you are using Report Builder then Language property will appear in Localization section.

-4

hi friend please try this expression your report

="Page " + Globals!PageNumber.ToString() + " of " + Globals!OverallTotalPages.ToString() + vbcrlf + "Generated: " + Globals!ExecutionTime.ToString()
Taryn
  • 242,637
  • 56
  • 362
  • 405
  • Folks, this does answer the question. The date is at the far right end of the expression. The extra info is useful too. Deserves more up votes imo. – Jeff May 26 '22 at 23:13