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

I Don't Understand How This Isn't The Answer

Hi, could anyone explain to me what this question is actually asking? I've done what the question wants, and it won't pass, or tell me why it's not passing.

The Question: When saving a date in a 'date' field, you need make sure the date is formatted properly. The correct format is YYYY-MM-DD.

Complete the function to convert a passed date into a SQL safe date and return the results using the following requirements:

Use the date() function to properly format the passed date. Use the strtotime() function to accept anything from a date in a different format to a string like 'yesterday'.

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

index.php
<?php

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Alex,

Your syntax is correct, but your formatting is not. Challenges are very specific and picky. Here, the instructions clearly state that:

The correct format is YYYY-MM-DD.

But you are formatting it as YYYY/MM/DD. Notice, the instructions wants dashes, and you are using slashes. Once that's corrected, the code passes.

Other than that, nice job! :) :dizzy:

Great work, to add to what Jason said, you are missing the closing of the PHP code block. That might have got copied over incorrectly but that could the next error if you try that the new formatting.

Jason Anders
Jason Anders
Treehouse Moderator 145,858 Points

Hi Ryan Richard

The closing tag actually wasn't missed in the copy/paste. When the code file is pure PHP, the closing tag is not needed. In fact, the preferred syntax, according to the PHP Documentation is to omit the closing tag with pure PHP files.

Either will compile and would be correct syntax, but the convention is to have no closing tag.

Keep Coding! :) :dizzy: