CodeIgniter Forums

Full Version: Order by Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my database column date_created_on the date and time is in php time() as shown in image below

Just need to make sure that even though my date_created_on gets inserted with time() that it still can sort it out by date.

On my end I see no problems. When view list


PHP Code:
public function getQuestions() {
$this->db->select('*');
$this->db->from('questions');
$this->db->order_by('date_created_on''desc');
$query $this->db->get();

if (
$query->num_rows() > 0) {
return 
$query->result_array();
} else {
return 
false;
}




[Image: 3HsL2TqvzR1U.png]

[Image: 3HsLRloOTOTo.png]
Yep should be fine. Though I'd recommend not using timestamps anymore. DateTime is more future proof Smile

Not to mention more readable when looking at your data.
(04-04-2017, 12:34 AM)JayAdra Wrote: [ -> ]Yep should be fine. Though I'd recommend not using timestamps anymore. DateTime is more future proof Smile

Not to mention more readable when looking at your data.

Thank you for that info. if i use DateTime would I need to change the type int(10)


Also do you have link for the DateTime so can read php manual.
Here are the docs:
http://php.net/manual/en/class.datetime.php

Yes you'd need to change the type to datetime. Keep in mind you may need to consider timezones, and if the user's timezone will vary. If using datetime, be sure to store all data in UTC timezone, and then on output convert to local time.
(04-04-2017, 03:23 AM)JayAdra Wrote: [ -> ]Here are the docs:
http://php.net/manual/en/class.datetime.php

Yes you'd need to change the type to datetime. Keep in mind you may need to consider timezones, and if the user's timezone will vary. If using datetime, be sure to store all data in UTC timezone, and then on output convert to local time.

Thank you.
Another thing I would rename your datetime fields. The new CI4 will be using ( created_at and updated_at )
fields in it's new model class.

Will save you time later if you need to convert to a CI4 app structure.