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

https://teamtreehouse.com/library/crud-operations-with-php/reading-and-writing-reports/working-with-dates, crud operatio

I can't find any solution to this Challenge even in MDN: "SO please, Help"?

index.php
<?php


function convert_date_sql($date) {    
  $date = strtotime($date);
  $date = date("yyyy-mm-dd",$date);
  return $date;    
}  ?>

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Benoit Tordeurs ! Actually, you're not far off on this one. But part of the problem is that you're overwriting the $date variable that is sent in. Also, you're trying to use the format they gave as an example as the arguments for the date function which isn't exactly correct.

I chose to return the results directly without creating new variables as it feels cleaner and more concise to me. But this is my opinion.

function convert_date_sql($date) {
    //add your code here
    return date('Y-m-d', strtotime($date));
}

It's just one line of code but it says essentially this: "Return the date with the year first, month second and day last. Separate these with a hyphen. Parse any English version of time like "tomorrow" or "yesterday" to a UNIX timestamp."

:bulb: You say that you didn't find any answers in the MDN documentation. But this is not surprising at all. MDN (Mozilla Developer Network) contains documentation about Open Web technologies such as HTML, CSS, and JavaScript. You will not find PHP documentation on MDN. Instead, you should be using the PHP documentation at php.net

To make this perfectly clear, PHP and JavaScript are two entirely different languages. Just as both English and Swedish are Germanic based languages, PHP and JavaScript are both programming languages, but they are both unique just as English and Swedish are distinct languages.

Hope this helps! :sparkles:

AMAZING !!!!!!!!! Whaowwww, I was looking for a solution for so long !!!!! Thank you Jennifer!