Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Reading and Writing Reports Working with Dates

Ronaldo Fialho
Ronaldo Fialho
5,105 Points

Converting date

<?php

function convert_date_sql($date) { //add your code here $results = date('Y/m/d', strtotime($date)); return $results; } echo convert_date_sql("yesterday");

Need help, guys!! it seems to me is converting to the right format. What can possible be wrong? it says i'm not returning the right date.

index.php
<?php

function convert_date_sql($date) {
    //add your code here
  $results =  date('Y/m/d', strtotime($date));
  return $results;
}
echo convert_date_sql("yesterday");

1 Answer

Michael Collins
Michael Collins
3,447 Points

Hi Ronaldo,

They are asking for the date format of YYYY-MM-DD.

So what you have done is correct, except you have used forward slashes rather than hyphens. It should be:

<?php
function convert_date_sql($date) {
    //add your code here
  $results = date('Y-m-d', strtotime($date));
  return $results;
}
echo convert_date_sql("yesterday");
?>