cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
NielsL
Level: Powered On

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
Fakhri
Level: Powered On

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.
   

10 REPLIES 10
Fakhri
Level: Powered On

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.
   

NielsL
Level: Powered On

Re: Format date-time as on this forum

@Fakhri, thanks. 

 

That was exactly what I was looking for. 

Fakhri
Level: Powered On

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 

NielsL
Level: Powered On

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
Level: Powered On

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

NielsL
Level: Powered On

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
Level: Powered On

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

NielsL
Level: Powered On

Re: Format date-time as on this forum

@Fakhri

 

I missed that as well. it works as supposed now Smiley Happy 

 

Thanks a for help. It is really appreciated. 

Fakhri
Level: Powered On

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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 347 members 5,198 guests
Please welcome our newest community members: