• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Joined rows in mdate() function?

#1
[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

#2
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.