cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

Format date-time as on this forum

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Frequent Visitor

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.
   

View solution in original post

10 REPLIES 10
Highlighted
Frequent Visitor

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.
   

View solution in original post

Highlighted
Helper IV
Helper IV

Re: Format date-time as on this forum

@Fakhri, thanks. 

 

That was exactly what I was looking for. 

Highlighted
Frequent Visitor

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 

Highlighted
Helper IV
Helper IV

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. 

Highlighted
Frequent Visitor

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

Highlighted
Helper IV
Helper IV

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

 

Highlighted
Frequent Visitor

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

Highlighted
Helper IV
Helper IV

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. 

Highlighted
Frequent Visitor

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"

 

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,456)