SQL 如何在 ssrs 报告中格式化日期和时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15975955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I format date and time on ssrs report?
提问by Neo
on SSRS report I need to show todays date and current time
在 SSRS 报告中,我需要展示 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.
我试过这个,=FormatDateTime(Now,"MM/dd/yyyy hh:mm tt")
但这对我不起作用,给出了一个错误。
Anyone please help me for expression
?
有人请帮我expression
吗?
I want output display like 4/12/2013 12:05 PM
我想要输出显示 4/12/2013 12:05 PM
回答by Ian Preston
=Format(Now(), "MM/dd/yyyy hh:mm tt")
Output:
输出:
04/12/2013 05:09 PM
回答by Jamie F
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.
如果日期和时间在它自己的单元格(又名文本框)中,那么您应该考虑将格式应用于整个文本框。这将创建更干净的导出到其他格式;特别是,该值将作为日期时间值而不是字符串导出到 Excel。
Use the properties pane or dialog to set the format for the textbox to "MM/dd/yyyy hh:mm tt"
使用属性窗格或对话框将文本框的格式设置为“MM/dd/yyyy hh:mm tt”
I would only use Ian's answer if the datetime is being concatenated with another string.
如果日期时间与另一个字符串连接,我只会使用 Ian 的答案。
回答by LCJ
I am using following in SSRS 2005
我在 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")
回答by Crezzer7
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:
在 SSRS 2016 中,属性标题“本地化”下有一个名为“ Calendar
”的选项,如果您单击它,它会为您提供以下 2 个选项:
- Gregorian (dd/mm/yyyy)
- GregorianUSEnglish (MM/dd/yyyy)
- 公历 (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
":
或者,如果这对您不起作用,请在“数字”下和单元格“ Format
”中指定以下格式之一:
dd/MM/yyyy
or MM/dd/yyyy
dd/MM/yyyy
或者 MM/dd/yyyy
回答by Shubham Bhangale
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
回答by Del Lee
The following is how I do it using Visual Studio 2017 for an RDL targetted for SSRS 2017:
以下是我将 Visual Studio 2017 用于针对 SSRS 2017 的 RDL 的方法:
Right-click on the field in the textbox on the design surface and choose Placeholder Properties. Choose the Numberpanel and click on Datein the Categorylistbox, then select the formatting you are looking for in the Typelistbox.
右键单击设计图面上文本框中的字段,然后选择Placeholder Properties。选择号码面板,然后单击日期在类别列表框,然后选择您正在寻找的格式类型列表框。
回答by Gul Saeed Khattak
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.
确保短日期字段等于“dd/mm/yyyy”。按应用。现在转到 SSRS 并右键单击空白处的报告并选择属性。
If you are using visual studio then set Language property equal to =User!Language.
如果您使用的是 Visual Studio,则将 Language 属性设置为等于 =User!Language。
If you are using Report Builder then Language property will appear in Localization section.
如果您使用的是报表生成器,则语言属性将出现在本地化部分。
回答by Tariq Khalaf
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
如果您单击报表上远离任何表格的空白处,然后查看属性,则其中一个 Misc 字段称为语言,它允许您选择要设置的语言,然后可以使用此设置
=FormatDateTime(now,x)
Which x
can be 1, 2, 3, 4, 5
这x
可以是1,2,3,4,5
回答by Laxman Gite
If you want date and time separate then use below expressions: Date and Time Expression
如果您想将日期和时间分开,请使用以下表达式: 日期和时间表达式
Expression1for current date : =formatdatetime(today)its return date is = 11/15/2016
当前日期的表达式 1:=formatdatetime(today)其返回日期为 = 11/15/2016
Expression2for current time : =CDate(Now).ToString("hh:mm tt")its return time is = 3:44 PM
当前时间的表达式 2: =CDate(Now).ToString("hh:mm tt")它的返回时间是 = 3:44 PM
This report printed on Expression1at Expression2
该报告打印在Expression1的Expression2 上
Output will be : Output of Both Expression
输出将是: 两个表达式的输出
This report printed on 11/15/2016at 3:44 PM
本报告于2016年11月15日下午 3:44打印
回答by Ronney
=Replace(Format(CDate(Now()),"MM.dd.yyyy"), ".", "/")