Jonob Posted July 23, 2009 Share Posted July 23, 2009 Hi all, Just getting to grips with the DateTime object in php - I need to have one of the objects in an array typed as DateTime, which is then sent via amfphp to a flex front end. So, what I have done, is after my array is created from a mysql query, I have a __construct function that does something like: $this->date_start = new DateTime($this->date_start); And this works perfectly - the date_start object in the array is sent as a DateTime object. The one area that I am having an issue, however, is that in certain cases I need to do some additonal php processing on that DateTime object in the array before it is sent....and this is where I am tripping up. I have tried to recast it back to a string using something like: $new_date = date("Y-m-d", $array->date_start) but I get an error message like date() expects parameter 2 to be long, object given Any ideas on how I can get around this? Thanks for any advice. Quote Link to comment https://forums.phpfreaks.com/topic/167195-solved-datetime-object/ Share on other sites More sharing options...
waynew Posted July 23, 2009 Share Posted July 23, 2009 What is actually in $array->date_start?? Quote Link to comment https://forums.phpfreaks.com/topic/167195-solved-datetime-object/#findComment-881539 Share on other sites More sharing options...
Jonob Posted July 23, 2009 Author Share Posted July 23, 2009 OK, managed to work this one out. I need to do something like: $new_date = date_format($vat_report[0]->date_start,'Y-m-d'); Basically, the date_format function converts a DateTime object into the format of your choosing. Just in case someone else has the same question at some point in time, the full list of DateTime functions is here: http://us2.php.net/manual/en/ref.datetime.php Quote Link to comment https://forums.phpfreaks.com/topic/167195-solved-datetime-object/#findComment-881543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.