Jump to content

i am a beginner and i really need some help.


cooks

Recommended Posts

hi there i am a beginner in PHP and i really would like some help with this.....

 

i need to make use of the date() function to retrieve the current date. Use the split() function to retrieve the day month and the year from the current date. and the calculations to display the age.

 

if anyone could help me with this it would be amazing.

 

thank you!!

newagecalc.php

You could format the output from the date() function so it contains some sort of separator. Then just use explode() to break apart the date. More information about both functions can be found in the PHP manual:

 

Side note: the split() function has been deprecated.

Or you could just do this 

<?php
$born = new DateTime("August 28, 1964");
$now = new DateTime();
echo $now->format("F j, Y");  // Output August 29, 2014 format:
echo '<br>';
$age = $born->diff($now);
echo "I am " . $age->y . " years old<br>";

More info on DateTime() here: http://php.net/manual/en/class.datetime.php

Maybe something like?  :confused:

$calendarDay = new DateTime( $month . ' ' . $day . ', ' . $year );
$age = $born->diff($calendarDay);

I just wrote first post on how easy it is to do it this way and the learning part is actually figuring it out on your own (in my opinion).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.