I have to convert date time before sending to mongodb. By googling found that I should use MongoDate class.
/* Fields */
Class MongoDate {
/* Fields */
public int $sec ;
public int $usec ;
/* Methods */
public __construct ([ int $sec = time() [, int $usec = 0 ]] )
public DateTime toDateTime ( void )
public string __toString ( void )
}
How to use inside my codeigniter project? I have tried creating a helper file and put the code exactly in there but got error unexpected 'int' when I remove 'int' from both $sec and $usec then I get error of syntax error, unexpected '__construct'
Thanks for help in advance.
Edited
This is my function
public function do_placeorder(){
$url = 'https://myapp.herokuapp.com/api/orders';
$ColDate = $this->session->userdata('ColRealDate');
$dt = new DateTime("@$ColDate");
include_once(APPPATH.'helpers/mongodate_helper.php');
$ColDT = new MongoDate(strtotime($dt->format('Y-m-d H:i:s')));
echo $ColDT;
}