Home Forums Chart Support How to print just the date when importing dateTime from PHP

How to print just the date when importing dateTime from PHP

Viewing 2 posts - 1 through 2 (of 2 total)
  • #17702

    Hi there,

    I am currently creating a page where you can view statistics from a game I made. I am importing date from a MySQL database with the a DateTime row. Now I want to display just the month and day on my x-axis, instead of year, month, day, and the exact time. I know there is a documentation, but I couldn’t find a working solution over there.

    I currently have this as the PHP:

    //Maak verbinding met server
    $servername = "..";
    $username = "..";
    $password = "..";
    $dbname = "..";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    $sql = "SELECT * FROM geometry_results WHERE " . $_SESSION['userID'] . " = userID ORDER BY datum asc";
    $result = $conn->query($sql);
    
    $dataPoints = array();
    
    if ($result->num_rows > 0) {
        // output data of each row
        while ($row = $result->fetch_assoc()) {
            $results = $row['goed'];
            $mes = date(2000, 10, 10);
    
            // $text = 'Time: ' . $row['time'];
    
            array_push($dataPoints, array("y" => ($row['tijd'] / 10), "label" => date($row['datum']), "wins" => $row['goed'], "false" => $row['fout']));
            // array_push($dataPoints, array('y' => Date(2012, 02, 02), "label" => $row['datum']));
    
        }
    } else {
        $results = "0 results";
    }
    
    $conn->close();
    

    And this as a script to load the statistics in a line diagram:
    https://hastebin.com/ekidupukuq.js

    • This topic was modified 6 years, 5 months ago by timyboy12345.
    #17711

    @timyboy12345,

    In the code snippet that you have shared, the date-time values being read from database are assigned as labels instead of assigning it as x values. Hence, setting the valueFormatString won’t work in this case. Instead, you can go with one of the following options:

    1) Format the date before assigning it to the label, or
    2) Pass it as date-time and assign it to x value. And format it using valueFormatString.

    ___________
    Indranil Deo,
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.