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

Link to comment
Share on other sites

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.

Edited by cyberRobot
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.