本文整理汇总了PHP中Carbon\Carbon::diffInYears方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::diffInYears方法的具体用法?PHP Carbon::diffInYears怎么用?PHP Carbon::diffInYears使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::diffInYears方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProfile
public function getProfile($userid)
{
$user = User::find($userid);
if (count($user) >= 1) {
$updated = new Carbon($user->updated_at);
$now = Carbon::now();
if ($updated->diff($now)->m < 1) {
$lastOnline = "Last seen less than a minute ago";
} elseif ($updated->diff($now)->h < 1) {
$lastOnline = $updated->diffInMinutes($now) > 1 ? sprintf("Last seen %d minutes ago", $updated->diffInMinutes($now)) : sprintf("Last seen %d minute ago", $updated->diffInMinutes($now));
} elseif ($updated->diff($now)->d < 1) {
$lastOnline = $updated->diffInHours($now) > 1 ? sprintf("Last seen %d hours ago", $updated->diffInHours($now)) : sprintf("Last seen %d hour ago", $updated->diffInHours($now));
} elseif ($updated->diff($now)->d < 7) {
$lastOnline = $updated->diffInDays($now) > 1 ? sprintf("Last seen %d days ago", $updated->diffInDays($now)) : sprintf("Last seen %d day ago", $updated->diffInDays($now));
} elseif ($updated->diff($now)->m < 1) {
$lastOnline = $updated->diffInWeeks($now) > 1 ? sprintf("Last seen %d weeks ago", $updated->diffInWeeks($now)) : sprintf("Last seen %d week ago", $updated->diffInWeeks($now));
} elseif ($updated->diff($now)->y < 1) {
$lastOnline = $updated->diffInMonths($now) > 1 ? sprintf("Last seen %d months ago", $updated->diffInMonths($now)) : sprintf("Last seen %d month ago", $updated->diffInMonths($now));
} else {
$lastOnline = $updated->diffInYears($now) > 1 ? sprintf("Last seen %d years ago", $updated->diffInYears($now)) : sprintf("Last seen %d year ago", $updated->diffInYears($now));
}
return view('dashboard.userProfile', ['user' => $user, 'lastOnline' => $lastOnline]);
} else {
return view('dashboard.userProfile');
}
}
示例2: lengthInYears
/**
* Get the difference between start and end dates of the period in years.
*
* @return int
*/
public function lengthInYears()
{
return $this->startDate->diffInYears($this->endDate);
}
示例3: report
/**
* [report description]
* @param [type] $token [description]
* @return [type] [description]
*/
public function report($token)
{
$affiliate = $this->affiliateRepository->token($token);
//Total dues for Affiliate
$duesAffiliate = $this->duesRepository->getModel()->where('type', 'affiliate')->where('affiliate_id', $affiliate->id)->orderBy('date_payment', 'ASC')->get();
//Total dues for Private
$duesPrivate = $this->duesRepository->getModel()->where('type', 'privado')->where('affiliate_id', $affiliate->id)->orderBy('date_payment', 'ASC')->get();
$error = '';
$page = 'Afiliados';
if ($duesAffiliate->isEmpty()) {
$error_affiliate = true;
}
if ($duesPrivate->isEmpty()) {
$error_private = true;
}
if (isset($error_private) && isset($error_affiliate)) {
$error = "El afiliado {$affiliate->fname} {$affiliate->flast} no cuenta con cuotas canceladas.";
return view('errors.validate', compact('page', 'error'));
}
//Birthdate
$birthdate = new Carbon($affiliate->birthdate);
//Age
$age = $birthdate->diffInYears(Carbon::now());
//Format Birthdate
$birthdate = $birthdate->format('d/m/Y');
//Data for report affiliate
$dataAffiliate = $this->prepareData($duesAffiliate, 'affiliate');
//Data for report private
$dataPrivate = $this->prepareData($duesPrivate, 'privado');
//Dues total max, date of admission
$dues_total_max = 0;
if ($dataAffiliate[count($dataAffiliate) - 1][2] >= $dataPrivate[count($dataPrivate) - 1][2]) {
$dues_total_max = $dataAffiliate[count($dataAffiliate) - 1][2];
$date_of_admission = $dataAffiliate[count($dataAffiliate) - 1][0];
} else {
$dues_total_max = $dataPrivate[count($dataPrivate) - 1][2];
$date_of_admission = $dataPrivate[count($dataPrivate) - 1][0];
}
//Date Now separed Date of Hours
$arrDateNow = $this->arrDateNow();
$pdf = \PDF::loadView('affiliates.report.main', compact('arrDateNow', 'affiliate', 'birthdate', 'age', 'date_of_admission', 'dataPrivate', 'dues_total_max', 'dataAffiliate'))->setOrientation('portrait');
return $pdf->stream("Reporte Contribución Afiliado -" . $affiliate->fullname() . ".pdf");
}
示例4: age
/**
*
*Get the age from the given date
*/
public function age()
{
$myTime = new Carbon($this->date_of_birth);
return $myTime->diffInYears();
}