-1

I am attempting to extract a date portion from a TIMESTAMP but not having much success. I initially tried selecting it in the query as a variable then extracting it, but Im assuming the syntax was incorrect for a string as it just said unexpected.

So im now trying to extract it using a selection query directly from the database using the following.

$date_added = mysqli_query($dbconnection,'SELECT DATE(date_added) FROM classifieds WHERE id = "'.$id.'"');

This query is being run inside a WHILE loop which has already selected the entire row and the rows identified $id. So ive set this to only look for the DATE from the current entry. When I run this however I get the following error:

Catchable Fatal Error - Object of Class mysqli_result could not be converted to a string in "website"

I'm obviously doing something wrong in the query but I cant see what.

Thanks

OJ102
  • 49
  • 8
  • possible duplicate of [Convert timestamp to date in MySQL query](http://stackoverflow.com/questions/9251561/convert-timestamp-to-date-in-mysql-query) – lighter May 29 '14 at 07:32
  • I have looked at the "possible Duplicate post" already and cant make it work, I was trying the following: $sql = "SELECT DATE(date_added, %Y %D %M) FROM classifieds WHERE id = $id "; I tried this one also and just got syntax errors #$querydate = 'SELECT from_unixtime(date_added, '%Y %D %M' ) FROM classifieds WHERE id = "'.$id.'"'; $date_added = mysqli_query($dbconnection, $sql); Nothing is being returned but the ID is registering later on in the script so there is definatly an $id here. – OJ102 May 29 '14 at 08:14

2 Answers2

0

Try check your "$id" to echo get_class($id), if show 'mysqli_result' - need truly convert

Are.exe
  • 51
  • 2
  • Sorry, I dont understand what your asking here. The $id in the loop is working as it is displayed later on from an array – OJ102 May 29 '14 at 08:29
  • see only part where variable $id concat like string - and you write about error - think should be check var $id vith echo get_class($id) – Are.exe May 29 '14 at 09:52
0

I found my answer eventually. import the TIMESTAMP as a string called say $date_added then use $date_added = date( 'Y-m-d', strtotime($date_added));

OJ102
  • 49
  • 8