Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Format date-time as on this forum

(1) ShareShare
ReportReport
Posted on by 306

Is it possible to format date/times as they are shown on this forum? E.g. 20 minutes ago, yesterday, Sunday etc.

As far as I can see, there's no out-of-the-box formatting to do this. This way of showing a date and time is much more userfriendly in my opinion than using ShortDate24, LongDate24 etc. 

 

Has anyone played around with this? Any input is appreciated. 

 

Capture.PNG

Categories:
  • Nielf Profile Picture
    Nielf 306 on at
    Re: Format date-time as on this forum

    @Fakhri

     

    I'll see if I can make improvements to the formula. E.g. it would be cool to add something like "last week", "two weeks ago" etc. 

     

    It's one of the small things, but I really think something like this improves the user experience. Users of the apps are used to seeing dates formatted like this on social media like LinkedIn, Twitter, Facebook etc.

  • Fakhri Profile Picture
    Fakhri 72 on at
    Re: Format date-time as on this forum

    Hi @NielsL

     

    Glad it worked just fine . Sorry for the mistake.

     

    Anyways hopefully you can make this even better since the formula I gave you isn't the best way, since not every month has 31 days in it. But the method used by our forum is actually quite smart as anything more than a week will return a date instead of my original formula which returns " months ago"

     

     

  • Nielf Profile Picture
    Nielf 306 on at
    Re: Format date-time as on this forum

    @Fakhri

     

    I missed that as well. it works as supposed now 🙂 

     

    Thanks a for help. It is really appreciated. 

  • Fakhri Profile Picture
    Fakhri 72 on at
    Re: Format date-time as on this forum

    Sorry @NielsL

    It seems one of the line of code was wrong. There is an extra "," the third line. Try eliminating that 1st and then we see whether that resolves the issue

  • Nielf Profile Picture
    Nielf 306 on at
    Re: Format date-time as on this forum

    @Fakhri

     

    Just to be sure: The formula is to be used on Text property, right? 

     

    I've updated the formula to be:

    If( DateDiff((scheduledend),Now(),Minutes)<60 , Concatenate(Text(DateDiff((scheduledend),Now(),Minutes))," mins ago"),
     DateDiff((scheduledend),Now(),Hours)<=24 , Concatenate(Text(DateDiff((scheduledend),Now(),Hours))," hours ago"),
     DateDiff((scheduledend),Now(),Days)<=31 , Text(scheduledend),,
     DateDiff((scheduledend),Now(),Months)<=12 , Concatenate(Text(DateDiff((scheduledend),Now(),Months))," months ago"),
     Concatenate(Text(DateDiff((scheduledend),Now(),Years))," years ago"))

    But that returns a series of errors. Could this be a copy/paste error?

    2.PNG

    The formula I use (which I hope to ditch) looks like this:

    Text(scheduledend, DateTimeFormat.LongDate)

    Which results in this:

    Monday, October 1, 2018

     

  • Fakhri Profile Picture
    Fakhri 72 on at
    Re: Format date-time as on this forum

    Hi again @NielsL

     I forgot I used a variable "NowTime". You can replace it with Now(). Not sure why I created that variable. Maybe I was intending to use it again in another formula. But once you change it to Now(), should run fine.

     

    If( DateDiff((Created),Now(),Minutes)<60 , Concatenate(Text(DateDiff((Created),Now(),Minutes))," mins ago"),
      DateDiff((Created),Now(),Hours)<=24 , Concatenate(Text(DateDiff((Created),Now(),Hours))," hours ago"),
      DateDiff((Created),Now(),Days)<=31 , Text(Created),,
      DateDiff((Created),Now(),Months)<=12 , Concatenate(Text(DateDiff((Created),Now(),Months))," months ago"),
      Concatenate(Text(DateDiff((Created),Now(),Years))," years ago"))

     

    Posting date indicator.png

  • Nielf Profile Picture
    Nielf 306 on at
    Re: Format date-time as on this forum

    @Fakhri

     

    Can you show some screenshots of your working formula in PowerApps?

     

    I'm getting some errors saying that Name isn't available. I have updated the formula with my date input so that doesn't seem to be the problem. 

     

    It's probably just me doing it wrong. 

  • Fakhri Profile Picture
    Fakhri 72 on at
    Re: Format date-time as on this forum

    Hi @NielsL

     

    Glad that help you. Anyways if you want similar result to the one you post, try this one instead:

     

    If( DateDiff((Created),NowTime,Minutes)<60 , Concatenate(Text(DateDiff((Created),NowTime,Minutes))," mins ago"),
      DateDiff((Created),NowTime,Hours)<=24 , Concatenate(Text(DateDiff((Created),NowTime,Hours))," hours ago"),
      DateDiff((Created),NowTime,Days)<=31 ,Text(Created,"[$-en-US]dddd"),
      DateDiff((Created),NowTime,Months)<=12 , Text(Created),
      Concatenate(Text(DateDiff((Created),NowTime,Years))," years ago"))
       

    The only difference is, when the date diff is more than 1 day then it will display the day of the week, if it is more than a week then it will just put the actual date. You have a nice day mate 

  • Nielf Profile Picture
    Nielf 306 on at
    Re: Format date-time as on this forum

    @Fakhri, thanks. 

     

    That was exactly what I was looking for. 

  • Verified answer
    Fakhri Profile Picture
    Fakhri 72 on at
    Re: Format date-time as on this forum

    Hi @NielsL

     

    I had tried something similar, but not quite the same. But I think it might help point you to the right direction 

     

    If( DateDiff((Created),NowTime,Minutes)<60 , Concatenate(Text(DateDiff((Created),NowTime,Minutes))," mins ago"),
      DateDiff((Created),NowTime,Hours)<=24 , Concatenate(Text(DateDiff((Created),NowTime,Hours))," hours ago"),
      DateDiff((Created),NowTime,Days)<=31 , Concatenate(Text(DateDiff((Created),NowTime,Days))," days ago"),
      DateDiff((Created),NowTime,Months)<=12 , Concatenate(Text(DateDiff((Created),NowTime,Months))," months ago"),
      Concatenate(Text(DateDiff((Created),NowTime,Years))," years ago"))

     

    You need to change the "Created" date to your data date. I'll give a bit of thinkering maybe some adjustment and you will get the result you want.
       

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,343

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard