Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

Flow condition using date not working when date is null

(0) ShareShare
ReportReport
Posted on by 12

I have a flow where the for a date column i am formatting this and adding it to an excel file.

 

When the date is null the flow fails as a string rather than null.

 

Any ideas on how to resolve this? below is the error message:

 

Unable to process template language expressions in action 'Formatted_case_resolved_date' inputs at line '1' and column '3097': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.

  • Pstork1 Profile Picture
    65,906 Most Valuable Professional on at
    Re: Flow condition using date not working when date is null

    Sure,  the code when using Coalesce would be as follows:

    formatDateTime(coalesce(triggerBody()?['efa_resolvedon'],'2021-01-01'),'yyyy/MM/dd')
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Flow condition using date not working when date is null

    HI @ryanb888 

     

    Your example is correct.

     

    if(empty(triggerBody()?['efa_resolvedon']),'',formatDateTime(triggerBody()?['efa_resolvedon'],'yyyy/MM/dd')) 

     

    Damien

  • ryanb888 Profile Picture
    12 on at
    Re: Flow condition using date not working when date is null

    thanks for your reply, my existing code is formatDateTime(triggerBody()?['efa_resolvedon'],'yyyy/MM/dd'))

     

    in your code provided would you be able to incorporate the trigger body? or is your code an alternative for formatting the data where trigger body is not required?

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Flow condition using date not working when date is null

    Nice one @Pstork1 !  Thank you for that. 👍

  • Pstork1 Profile Picture
    65,906 Most Valuable Professional on at
    Re: Flow condition using date not working when date is null

    Empty() is for determining Empty strings.  The better choice here would be to use Coalesce().  Coalesce process the parameters from left to right and accepts the first one that isn't null.  So you can supply your date as the first entry and a default date as the second.  If the first entry is null the second will be used.  Something like this

    formatdatetime(colalesce(DateTimeField,'1900-01-01'))
  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Flow condition using date not working when date is null

    Hi @ryanb888 

     

    Without seeing the action you are using, you could use a compose with an if expression.  For example:

     

    if(empty(dynamicdatevalue),'',formatdatetime(etcetc,'yyyy-MM-dd'))

     

    This would check for your date value being empty, and if so output '', otherwise it would use the formatdatetime.

     

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


    P.S. take a look at my new blog here

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow