0

As you can probably guess from the title, I am trying to use the formula =[Today] in a calculated field. I then use this field to compare two date fields. These represent start and end dates. Lastly, I have a fourth calculated column in which I determine if the "Today" field's value lies within those of Start and End.

Here is an excerpt from my schema.xml:

<Field ID="" Name="ProjectStartDate" DisplayName="$Resources:StartFieldString;" Type="DateTime" Format="DateOnly" Required="TRUE" Group="Site Columns"></Field>
<Field ID="" Name="ProjectEndDate" DisplayName="$Resources:EndFieldString;" Type="DateTime" Format="DateOnly" Required="TRUE" Group="Site Columns"></Field>
<Field ID="" Name="ProjectToday" DisplayName="$Resources:TodayFieldString;" Type="Calculated" Required="TRUE" Group="Site Columns">
  <Formula>
    =[Today]
  </Formula>
      </Field>
<Field ID="" Name="ProjectActive" Type="Calculated" ResultType="Boolean" DisplayName="$Resources:IsActiveField;" ReadOnly="TRUE">
  <Formula>
    =IF(AND([ProjectToday] > [StartDate], [ProjectToday] < [EndDate]), "true", "false")          
  </Formula>
  <FieldRefs>
    <FieldRef Name="StartDate" ID=""/>
    <FieldRef Name="EndDate" ID=""/>
    <FieldRef ID="" Name="ProjectToday"/>
  </FieldRefs>
</Field> 

I also tried putting =IF(AND([Today] &gt; [StartDate], [Today] &lt; [EndDate]), "true", "false") into the formula because the < sign was underlined red in editor.

Does anybody know what I'm doing wrong? I don't get any meaningful error, just the above one. Even in ULS I get nothing.

EDIT: I don't know why but now I get a more meaningful error when deploying it with the < and > signs: Illegal syntax. Expecting valid start name character. I guess this error is about the red underlined < sign in markup editor. But how to fix if this syntax comes from Microsoft's site?

1 Answer 1

0

You can not use TODAY calculations in a Calculated Column, because ListItems do not update like Excel Cells do.

You can do JavaScript Today calculations

How to use Today and Me in Calculated column

3
  • oh, I read somewhere that it is possible to use =[Today], but not =IF([Today] < [Date]). Well, then I guess I need to try JS. Commented Oct 6, 2015 at 20:30
  • Thats when you use [TODAY] in a View Filter, functions do not work in a Filter, but you can do calculations like [TODAY]+31 Commented Oct 7, 2015 at 8:36
  • ok then I guess I was just confused about the usage. I did away with the boolean calculated field and do the checking in code behind instead. not as slim of a solution as I hoped for, but it does what I needed. Commented Oct 7, 2015 at 9:17

Your Answer

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

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