如何格式化日期以包含周数?

How do I format the date to include the week number?

我正在使用 Microsoft Business Intelligence Development Studio 2012 尝试创建一个计算字段,它将为我提供名称为 'createdon'.

的字段的月份和周数

我是 SQL 的新手,经过一番研究,这是我想出的代码。

=Format(Fields!createdon.Value, "MMMM") & " Week " & (Int(DateDiff("d",DateSerial(Year(Fields!createdon.Value),Month(Fields!createdon.Value),1), Fields!FullDateAlternateKey.Value)/7)+1).ToString

但我收到错误消息:

"The Field expression for the dataset 'Dataset1' refers to the field 'FullDateAlternateKey'. Report item expressions can only refer to fields within the current datasetscop or, if inside an aggregate, the specified dataset scope. Letters in the names of fields my use the correct case.

我知道这意味着 "FullDateAlternateKey" 不是有效的字段名称,但我不知道要替换为哪个字段名称来更正此表达式。有没有经验丰富的人知道我该如何纠正这个问题?

理想情况下,我希望将其格式化为具有显示 "week ending in " 的列。 所以从 9/26/2015 到 10/2/2015 的任何日期都会说 "Week of 10/2/2015"

试试这个:

="Month: " & Datepart("m", Fields!createdon.Value) & " Week: " &
Datepart(DateInterval.WeekOfYear,Fields!createdon.Value)

您将获得以下内容:Month: 10 Week: 43

编辑您的问题并添加所需结果的示例,以帮助您确定特定格式。

更新:

试试这个:

="Today: " & Format(Fields!createdon.Value,"dd/M/yyyy") & "Week Of: " & Format(
DATEADD("d" ,7-DATEPART(DateInterval.WeekDay,Fields!createdon.Value,FirstDayOfWeek.Monday),Fields!createdon.Value),
"dd/M/yyyy")

它将显示:Today: 19/10/2015 Week Of: 25/10/2015