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

Raman Matthew
Raman Matthew
6,127 Points

I don't know to put strtotime function in this task

Function requirement in the correct format

index.php
<?php

function convert_date_sql($date) {
    //add your code here
  $sql = 'SELECT * FROM projects WHERE date = strtotime"YYYY-MM-DD"';


  try {
        $results = $db->prepare($sql);
        $results->bindValue(1, $date, PDO::PARAM_INT);
        $results->execute();
    } catch (Exception $e) {
        echo "Error!: " . $e->getMessage() . "<br />";
        return false;
    }
    return $results->fetch();
}

Hey Raman,

You'll use a placeholder for date in the sql query. Then assign $date to a string. Use the DateTime object instead of strtotime. It's cleaner:

$date = (new \DateTime)->format('Y-m-d');