Welcome Guest, Not a member yet? Register   Sign In
Order by Question
#1

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]
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(This post was last modified: 04-04-2017, 12:35 AM by JayAdra.)

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.
Reply
#3

(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.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

(This post was last modified: 04-04-2017, 03:23 AM by JayAdra.)

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.
Reply
#5

(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.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#6

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB