Return the absolute value of a number.

float abs( float number )


{abs(3.2)}  = 3.2 
{abs(-3.2)} = 3.2

Show a Prompt for a User to Login Based on a “last_login_date” Custom Field

Use Case: You’re storing as a user variable “last_login_date” and want to find the number of days since a user last logged in. Using abs(), time(), and int(), you can output a reader-friendly to encourage people to log back in.


{daysSinceLastLogin = (time(last_login_date) - time("now"))/86400}
{friendlyDays = int(abs(daysSinceLastLogin))}
You haven't logged in in the past {friendlyDays} days!


On the user profile:

zephyr example last_login_date

“You haven’t logged in in the past 5 days!”

Explanation: This script uses the time() function to create a UNIX timestamp of each user’s last_login_date, which then subtracts the value of the current UNIX timestamp, and finally divided by 86400, the number of seconds in a day. This provides the number of days since the user’s last login, which is display as a negative float number, for example, -82.4795. Using the abs() function, the absolute value of that number is taken, converting -82.4795 to 82.4795. Within the same script, the int() function is used to round that value to the nearest whole number, converting 82.4795 to simply 82. This value is assigned to the local variable “friendlyDate”. Finally, the “friendlyDate” variable is called within the template, and the number of days since last login will display for each user.