0

I'm trying to get the data in this array, I simply need DATELOGGED and DATECLOSED to be set as variables so i can handle them elsewhere in my script, however no matter what i do i get an array containing the results and not just the results.

obviously my understanding of handling an array are not up to scratch, can anyone help point me in the right direction please as everything i have read so far doesn't seem to cover this.

multi-dimensional array?!?

Here's my Script so far:

            //QUERY ASSYST
                $assystQ =
                "       
                SELECT 
                PRODUCT_N,
                MAX(INCIDENT.INCIDENT_REF) MAX_INCIDENT_REF,
                MAX(DATE_LOGGED) DATELOGGED,
                MAX(inc_close_date) DATECLOSED,
                DATEDIFF(DAY,MAX(DATE_LOGGED),GETDATE()) DAYS_SINCE
                FROM INCIDENT
                LEFT JOIN ITEM
                ON INCIDENT.ITEM_ID = ITEM.ITEM_ID
                LEFT JOIN PRODUCT
                ON ITEM.PRODUCT_ID  = PRODUCT.PRODUCT_ID
                WHERE EVENT_TYPE    = 'i' 
                AND INC_SERIOUS_ID  = '$alertType'       
                AND product_n       = '$assystProductName' 
                AND inc_status      = 'c' 
                GROUP BY PRODUCT_N
                ";
                $assystR            = sqlsrv_query($assystconn, $assystQ);
                while ($ResultOobj  = sqlsrv_fetch_array($assystR))
                {

        // CONVERT RESULTS
        $incidentReferance   = $ResultOobj[MAX_INCIDENT_REF];
        $incidentOpen        = $ResultOobj[DATELOGGED];

        //ECHO RESULTS
        var_dump($incidentOpen);
        echo "<br>Last Incident Referance: " .$incidentReferance;
                };

Here's what the var_dump is returning

I just don't understand how to get that date out of the array and into a single string.

object(DateTime)#5 (3) { ["date"]=> string(26) "2014-10-20 09:41:40.140000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Dublin" }
3
  • can you please print_r $Result0obj ? Commented Jul 18, 2016 at 10:46
  • stackoverflow.com/questions/4016727/… Commented Jul 18, 2016 at 10:48
  • print_r returns DateTime Object ( [date] => 2013-10-10 11:17:18.927000 [timezone_type] => 3 [timezone] => Europe/Dublin ) Commented Jul 18, 2016 at 11:05

1 Answer 1

2

You could look at PHP Docs and use this:

$time = date('Y-m-d', $incidentOpen->getTimestamp());

DateTime is an object and not an array. It has methods to get data from it. You can format your result datetime with function date().

Or if you just need its value date:

$time = $incidentOpen->date;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this worked perfectly my final code looked like this: $openDate= date('Y-m-d h:i:s', $incidentOpen->getTimestamp()); echo $openDate;

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.