Sradesign Posted April 7, 2016 Posted April 7, 2016 Hi I'm trying to find a way to show pages detail based on filtered date for example I want to get the pages that created this week how to achieve this with selector? mind you I'm not looking for past 7 days I want for the current week. Best Regards, Ali.M
netcarver Posted April 7, 2016 Posted April 7, 2016 If you take a view on what day a week starts on, you can use the PHP function strtotime() to get the timestamp of the last time that day happened and format it using date() to get it as a string for use in your find/filter selector. For example, if you decide a week starts on Monday, then this should get you a value you can use in selectors... $when = 'Last Monday'; $timestamp = strtotime($when); $date = date('Y-m-d', $timestamp); //echo "The date $when was $date\n"; Untested, YMMV. 1
alxndre Posted April 7, 2016 Posted April 7, 2016 If your week starts on sunday $d = strtotime("today"); $start_week = strtotime("last sunday midnight",$d); $end_week = strtotime("next saturday",$d); $start = date("Y-m-d",$start_week); $end = date("Y-m-d",$end_week); and then filter your pages like this: $results = $pages->find("datefield>=$start_week, datefield<=$end_week"); where datefield is whatever date field you are trying to filter. 5
kongondo Posted April 7, 2016 Posted April 7, 2016 (edited) Since you asked for 'created' you can swap datefield in the example by @Alxndre' for created (we also have 'published') Edited April 7, 2016 by kongondo 2
Sradesign Posted April 8, 2016 Author Posted April 8, 2016 Since you asked for 'created' you can swap datefield in the example by @Alxndre' for created (we also have 'published') Yup, just like that. If your week starts on sunday $d = strtotime("today"); $start_week = strtotime("last sunday midnight",$d); $end_week = strtotime("next saturday",$d); $start = date("Y-m-d",$start_week); $end = date("Y-m-d",$end_week); and then filter your pages like this: $results = $pages->find("datefield>=$start_week, datefield<=$end_week"); where datefield is whatever date field you are trying to filter. Thank you all I did it like below : // Today Registrations $todaydate = strtotime("today"); $today_registrations = $users->count('roles=member,created>='.$todaydate); // This Week Registrations $weekdate = strtotime("last sunday midnight",$todaydate); $week_registrations = $users->count('roles=member,created>='.$weekdate); 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now