CodeIgniter Forums
Joined rows in mdate() function? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Joined rows in mdate() function? (/showthread.php?tid=11586)



Joined rows in mdate() function? - El Forum - 09-15-2008

[eluser]Joakim_[/eluser]
I have a model where todays entries are shown for the user. However, I want the user's time-zone and daylight settings to be considered. I have tried to join these settings from the account table but I don't know how to include them in the mdate() function.

I've tried with the code below but it wont work:

Code:
function todays_posts()
    {
        $this->db->select('*');
        $this->db->from('posts');
        $this->db->join('accounts', 'account_id = post_account_id');

        $this->db->where('DAY(FROM_UNIXTIME(post_date))', mdate('%d', gmt_to_local(now(), 'accounts.timezone', 'accounts.daylight')));    
        
        return $this->db->get();
    }

Any help are much appreciated. Thank you very much! Smile


Joined rows in mdate() function? - El Forum - 09-15-2008

[eluser]xwero[/eluser]
Are you trying to use database field values in a CI helper function?
Code:
mdate('%d', gmt_to_local(now(), 'accounts.timezone', 'accounts.daylight'))
This won't work as you discovered.

What you could do is something like
Code:
$this->db->where(array('post_date'=>time(),'accounts.timezone'=>$timezone,'accounts.daylight'=>$daylight);
The timezone and daylight variables come from the information the user provided you.