Need to create a function in PHP that accepts a date as a parameter, and returns
ID: 646589 • Letter: N
Question
Need to create a function in PHP that accepts a date as a parameter, and returns a string that includes:
1. The day of the week, and
2. The number of days until that date.
You will use that function in the following code:
$datearray = array("1/1/2016", "11/16/2015", "9/1/2015");
foreach ($datearray as $key => $date) {
echo(myDateFunction($date));
}
?>
As you can see, the function you are creating is called myDateFunction. Your function should work if you add more dates to the array. You also need to add one date in the past, and figure out what to do in your function to address that in a user-friendly way. This is also a great opportunity to learn about the date function. This page on finding the difference between two dates should also be helpful: http://thisinterestsme.com/calculating-difference-dates-php/
Explanation / Answer
<?php
$test = new DateTime('02/31/2011');
echo date_format($test, 'Y-m-d H:i:s'); // 2011-03-03 00:00:00
$test = new DateTime('06/31/2011');
echo date_format($test, 'Y-m-d H:i:s'); // 2011-07-01 00:00:00
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.