Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/167195-solved-datetime-object/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.