laravel calculus age

1

Help I need to calculate the age, I have the date of birth but I do not find the function, this is what I have

<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"">
				<div class="form-group">
					<label for="fecha_nacimiento">Fecha Nacimiento</label>
					<p>{{ $alumno->fecha_nacimiento}}</p>
				</div>
			</div>

			<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"">
				<div class="form-group">
					<label for="edad">Edad</label>
					<p>{{ Carbon::createFromDate($alumno->fecha_nacimiento)}}</p>
				</div>
			</div>

I tried with carbon but it does not give me the result, it throws me error, does anyone know how to use that function createFromDate ??

    
asked by Edgardo Escobar 24.05.2017 в 02:45
source

1 answer

3

Assuming that the date you have stored in $alumno->fecha_nacimiento is expressed in some valid format, such as 1990-10-25, using the parse method to convert the date and the age property, you should get what you are looking for (in years):

$edad = Carbon::parse($alumno->fecha_nacimiento)->age; // 1990-10-25
dump($edad) // 26

As indicated by the Carbon documentation, if you want to use the createFromDate () method, you must write each component of the date separated by a comma:

Carbon::createFromDate(1990, 10, 25)->age;
    
answered by 24.05.2017 / 05:10
source