[eluser]Taff[/eluser]
I'm having a little trouble manipulating data after I get it from a database.
The date I am displaying should be in a different format to how it is being stored in the database (2008-04-30) for example.
Currently the user selects a date by using a date picker which creates a date in this format (which is nice and readable at least from a European point of view): 25/04/2008
Before I put these into the database field which has a "type" of date I am manipulating them using
Code:
function add(){
$_POST['start']=$this->_makeDate($_POST['start']);
$this->db->insert('projects',$this->db->escape($_POST));
}
function _makeDate($str){
$splitDate = explode("/",$str);
$newDate = $splitDate[2]."-".$splitDate[1]."-".$splitDate[0];
return $newDate;
}
which works well, and then I'm throwing it into the database.
Ideally I would like to do the opposite when I'm retrieving it from the database before sending it to the view. No matter what I have tried, I'm getting nowhere fast.
Code:
$tmp = $this->db->query($sql, array($id));
$tmp2 = $tmp->result();
// returns array(1) { [0]=> object(stdClass)#14 (5) { ["id"]=> string(2) "30" ["title"]=> string(11) "new project" ["notes"]=> string(12) "changed name" ["start"]=> string(10) "2008-04-26" ["company"]=> string(1) "0" } }
$tmp3 = $tmp2[0];
//returns object(stdClass)#14 (5) { ["id"]=> string(2) "30" ["title"]=> string(11) "new project" ["notes"]=> string(12) "changed name" ["start"]=> string(10) "2008-04-26" ["company"]=> string(1) "0" }
Any attempts to retrieve anything from $tmp3 return
Quote:Cannot use object of type stdClass as array in
How could I access that part of the object, manipulate the date and then return the result?
The second part of my question is that I can't help but wonder if I could be placing the date (in it's original format) into the database and still be able to access it
I'm aware that these questions are possibly not CI related, more to my lack of knowledge of objects in PHP.
Thanks in advance!
Taff