How do I format date and time on ssrs report?
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)
Based on comment:
=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy hh:mm.ss")
OR
=Format(CDate(Globals!ExecutionTime), "MM-dd-yyyy HH:mm.ss")
=Format(Now(), "MM/dd/yyyy hh:mm tt")
Output:
04/12/2013 05:09 PM
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
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.