Back to list

Carbon - Date Utilities

Lv.5749@mukitaro13 playsDec 31, 2025

Carbon date library helper class with common date operations.

preview.php
PHP
1class DateHelper
2{
3 public function formatDate(string $date): string
4 {
5 $carbon = Carbon::parse($date);
6 return $carbon->format('Y-m-d');
7 }
8
9 public function daysBetween(string $start, string $end): int
10 {
11 $startDate = Carbon::parse($start);
12 $endDate = Carbon::parse($end);
13 return $startDate->diffInDays($endDate);
14 }
15
16 public function isWeekday(string $date): bool
17 {
18 return Carbon::parse($date)->isWeekday();
19 }
20
21 public function addDays(string $date, int $days): string
22 {
23 return Carbon::parse($date)->addDays($days)->toDateString();
24 }
25
26 public function getMonthName(string $date): string
27 {
28 return Carbon::parse($date)->monthName;
29 }
30}

Custom problems are not included in rankings