Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
peter_werk
Frequent Visitor

Substract 10 minutes from TimeDate.UtcNow()

Hello I have a problem with subtracting minutes from time now in UTC timezone. The problem if reformatting the date 

 

Expression.Error: We cannot convert the value #datetimezone(2023, 5, 5, 8, 17, 6.4582182, 0, 0) to type DateTime.
Details:
Value=5/5/2023 8:17:06 AM +00:00
Type=[Type]

 

 

 

 

 

let
    // get the current UTC time
    utcNow = DateTimeZone.UtcNow(),

    // convert UTC time to the local time zone
    localTime = DateTimeZone.ToLocal(utcNow),

    // subtract 10 minutes from the local time
    tenMinutesAgo = localTime - #duration(0, 0, 10, 0),

    // convert the local time to a DateTime value
    dateTimeValue = DateTimeZone.ToLocal(tenMinutesAgo),

    // format the local time as a string in the ISO 8601 format
    formattedTime = DateTime.ToText(dateTimeValue, "yyyy-MM-ddTHH:mm:ss"),

    // construct the API URL with the formatted time parameter
    apiUrl = "MY API URL" & "?group=ba5bd6e6-d513-42b7-8a68-5830d67a32a6" & "&after=" & formattedTime,

    // make the API request and parse the JSON response
    Source = Json.Document(Web.Contents(apiUrl, [Headers=[Authorization="token MY API TOKEN"]])),
    #"Converted to Table" = Table.FromRecords({Source}),
    #"Expanded results" = Table.ExpandListColumn(#"Converted to Table", "results"),​

 

 

 

 

1 ACCEPTED SOLUTION
2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @peter_werk ,

 

If you want to format the datetime to a fixed format. You could do as follows.

formattedTime =Number.ToText(Date.Year(dateTimeValue))&"-"&Text.PadStart(Number.ToText(Date.Month(dateTimeValue)),0,"2")&"-"&Text.PadStart(Number.ToText(Date.Day(dateTimeValue)),0,"2")&"T"&Text.PadStart(Number.ToText(Time.Hour(dateTimeValue)),0,"2")&":"&Text.PadStart(Number.ToText(Time.Minute(dateTimeValue)),0,"2")&":"&Text.PadStart(Number.ToText(Number.RoundUp(Time.Second(dateTimeValue))),2,"0"),

 

vstephenmsft_0-1683685365672.png

You can download my attachment for details.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

ChielFaber
Super User
Super User

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors