Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

masterpowers's avatar

Make a return Date React like Carbon diffforhuman method in Vue

Hi Can Anyone Tell me How i can CHange a timestamp from an Api call to mutate it to like this

 last 59 minutes ago.

using Vue?

If i Use Carbon Diffhuman to GIve me a result like that i wont be reactived and it will be static... So Im Wondering if I can Do it in Vue and make it reactive. that everytime the time passes by it is recomputing a dynamic Cardbon diffhuman function

0 likes
6 replies
bobbybouwmann's avatar

You ask about Carbon in your title and now you refer to Vue.. That is kinda misleading!

Since you are working with vue, which is just javascript, you can use this: http://momentjs.com/

3 likes
masterpowers's avatar

Sorry I edited my first post , yup im bit confuse... Since if I return Carbon Instance from an api call with Diffhuman $data['date_joined'] = Carbon::now()->diffForHumans();
ill get a result lets say last 59 minutes but it is static and wont be reactive anymore...

trevorg's avatar

Just in case anyone else finds this, here is what I did:

1 - Return database field as Carbon object, accessible via API, in UTC. 2 - Create a filter in Vue to manipulate the date to display in user's timezone.

Vue.filter('moment', function(value, format) {
            return moment.utc(value).local().format(format);
        });

3 - Then in your template:

{{ comment.created_at | moment 'ddd, MMM D, h:mma' }}

In your case, you want to use moment's fromNow() method:

Vue.filter('timeago', function(value) {
            return moment.utc(value).local().fromNow();
        });
{{ comment.created_at | timeago }}
3 likes

Please or to participate in this conversation.