sadium/layouts/shortcodes/age.html

18 lines
411 B
HTML
Raw Normal View History

2024-06-15 20:59:38 +03:00
{{ $birth := "2000-10-28" | time }}
{{ $today := now }}
{{ $age := sub $today.Year $birth.Year }}
{{ $monthDiff := sub $today.Month $birth.Month }}
{{ $dayDiff := sub $today.Day $birth.Day }}
{{ if (gt $monthDiff 0) }}
{{ $age }}
{{ else if (lt $monthDiff 0) }}
{{ sub $age 1 }}
{{ else }}
{{ if (ge $dayDiff 0) }}
{{ $age }}
{{ else }}
{{ sub $age 1 }}
{{ end }}
{{ end }}