I’m trying to get month from two date time values so that I can compare them in a <<if[]>> condition.
Using <<[new DateTime().Month]>> I am able to get “9” to output.
But if I try <<[startdate]>> – <<[startdate.Month]>> it only outputs the following:
9/6/2023 2:00:00 PM –
@airbags It is perfect that you managed to find a solution. Date value from JSON source is read as nullable DateTime? type. To use DateTime.Month property it is required to cast nullable DateTime? type to DateTime. For example see the following code:
string json = "{\"startdate\": \"2023-09-05T14:00:00Z\"}";
JsonDataSource jsonData = new JsonDataSource(new MemoryStream(Encoding.UTF8.GetBytes(json)));
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("<<[((DateTime)startdate).Month]>>");
ReportingEngine engine = new ReportingEngine();
engine.KnownTypes.Add(typeof(DateTime));
engine.BuildReport(doc, jsonData);
doc.Save(@"C:\Temp\out.docx");