-e switch of
useradd expects a date in the international date format (
YYYY-MM-DD) as can be taken from its man page:
-e, --expiredate EXPIRE_DATE
The date on which the user account will be disabled. The date is
specified in the format YYYY-MM-DD.
You now simply have to state the date the account is supposed to expire. You can do this calculation in PHP. The answer you linked to does it using a standard command line tool so no high-level language has to be used.
Here is example code of how to do it in PHP:
$diffHour = 0;
$diffMinute = 0;
$diffSecond = 0;
$diffMonth = 10;
$diffDay = 0;
$diffYear = 0;
$hour = date("H") + $diffHour;
$minute = date("i") + $diffMinute;
$second = date("s") + $diffSecond;
$month = date("n") + $diffMonth;
$day = date("j") + $diffDay;
$year = date("Y") + $diffYear;
$time = mktime($hour, $minute, $second, $month, $day, $year);
$date = date("Y-m-d", $time);
Just fill in the variables in the top-most block. I filled them in for your 10 months example. You can go back in time, too. For example, if you want it to expire in in 7 months minus 4 days, you can set
$diffMonth = 7; and
$diffDay = -4;.
Then, pass the date value (
2018-02-09 when run today (except if you live in America, then it's a day earlier because we're still using a retarded time system with time zones)) to your bash script.
Example bash code:
useradd -e "2018-02-09" "rizal"