0

I have a specific problem regarding the mysql Datetime format to store the date and time together in table, so I have stored values in the table and now I want to retrieve those values and then compare that time with current datetime but things are going horribly wrong. this is what i tried so far..

<?php
    date_default_timezone_set('Asia/Calcutta');
    require_once('connect.php');

    $query="select matchTime from fixture_list where value1='Mumbai'";
    if($result= mysqli_query($con,$query)){
        while($row=mysqli_fetch_assoc($result)){
            print_r($row);
        }
        mysqli_free_result($result);
    }

    //$target = new DateTime('2018-07-27 01:00:00');
    $target = new DateTime($query);
    $now = new DateTime;
    $diff = $target->diff($now);

    if ($target > $now) {
        echo $diff->format('%a days, %h hours, %i minutes to go');
    } 
    else {
        echo $diff->format('%a days, %h hours, %i minutes too late');
    }
?>

My only purpose is to get the datetime value in string propbably which has been stored in the database and pass it to $target variable and then compare with $now, this is the error I m getting "Array ( [matchTime] => 2018-07-27 00:00:00 ) Array ( [matchTime] => 2018-07-27 00:00:00 ) Array ( [matchTime] => 2018-07-28 01:00:00 ) Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (select matchTime from fixture_list) at position 0 (s): The timezone could not be found in the database'"

1 Answer 1

1

This line:

$target = new DateTime($query);

should be:

$target = new DateTime($row['matchTime']);
Sign up to request clarification or add additional context in comments.

9 Comments

How to use where clause in matchTime inside row??
I'm not sure what you mean?
I mean table has multiple rows , but I want to retrieve Datetime of any perticular row at a time so I will have to apply some constrains like where clause
Isn't that what you are doing with where value1='Mumbai'? Or perhaps you want something like where matchTime > NOW() - INTERVAL 7 DAY?
Ya what I am doing with where value1='mumbai', will this work ??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.