0

I am trying to make a custom PHP field that returns the value of 'user last access' field as an integer of minutes 'time ago'.

I have created a normal views field for 'user last access' which returns almost exactly what I want from the normal field value:

x mins - this being x mins time ago, created by using 1 as the time units to display.

I just don't know how to return this value through a new PHP field that just references and displays the integer value for this field without ' mins' text ?

I want to then take this raw value and use a conditional statement of:

If user last access is less than 3 minutes print 'Online' else Print 'Offline'

0

In User Last access field UI, under the Date Format, select 'Custom' and then enter custom date format. For minutes you can enter 'i' which will show the number.

Refer http://php.net/manual/en/function.date.php for date formats.

Thanks

| improve this answer | |
  • Hi appreciate your help but a few things... I need it to show 'TIME AGO'. and using 'CUSTOM' date will only return their last access date not time ago since this. And also the main part of the question was how to return this raw data in a Views PHP field. – Ryan Aug 17 '16 at 23:02
  • You can create views template file to modify/alter the output of the field. If you are getting '3 mins ago' as field output, then in template file you can explode this string and get value 3 into the array. Then you can use that value to show the 'Online' or 'Offline' text. – Hiraman Patil Aug 18 '16 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.