Forum Discussion
Defining today's date on advanced editor
Hi Anonymous ,
Please have a try.
let
url = "https://my.url.com/Report/SomeReport",
body = "{""DtInicio"": Date.FromText("2022-10-01"),""DtFim"": DateTime.LocalNow()}",
Source = Json.Document(Web.Contents(
url,
[Headers = [#"Content-Type"="application/json", #"Authorization"="XXXXXX-8784"],
Content = Text.ToBinary(body)]))
in
#"Source"
The ""2022-10-01"" returns a text value instead of date type.
So it returns the error.
Date.FromText - PowerQuery M | Microsoft Learn
DateTime.LocalNow - PowerQuery M | Microsoft Learn
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello, Polly.
When I used this code you provide I got this error message:
Token comma expected
body = "{""DtInicio"": Date.FromText("2022-10-01"),""DtFim"": DateTime.LocalNow()}",
I tried myself tweak this not to get the error, but this new message pops up:
inicio = Date.FromText("2022-10-01"),
hoje = DateTime.LocalNow(),
body = "{""DtInicio"": " & inicio & ",""DtFim"": " & hoje & "}",
Expression.Error: We cannot apply operator & to types Text and Date.
Details:
Operator=&
Left={"DtInicio":
Right=10/1/2022
Just a remark: even if I don't use the clauses inicio and hoje, the very same error appears.
Your solution seems to work, but I cannot work through this problem.
Thanks for your response.
- Anonymous3 years agoNot applicable
Hi Anonymous ,
Please have a try.
let url = "https://my.url.com/Report/SomeReport", body = "{""DtInicio"": #date(2022,10,1),""DtFim"": DateTime.LocalNow()}", Source = Json.Document(Web.Contents( url, [Headers = [#"Content-Type"="application/json", #"Authorization"="XXXXXX-8784"], Content = Text.ToBinary(body)])) in #"Source"Check the value type.
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous3 years agoNot applicable
Hey, Anonymous . Once again, thanks for your help.
I've replicated this code you provided me, but this error message pops up:
Details: statusCode=500 mensagem=Unexpected character encountered while parsing value: #. Path 'DtInicio', line 1, position 13.I've also tried to insert this symbol &, but it also bears in error:
body = "{""DtInicio"":" & #date(2022,10,1) & ",""DtFim"":" & DateTime.LocalNow() & "}", Expression.Error: We cannot apply operator & to types Text and Date. Details: Operator=& Left={"DtInicio": Right=10/1/2022Do you know what else can be done to make this error message disappear?