How to create a rule on QGIS to show only features that have last week as date?











up vote
2
down vote

favorite












Basically I have a PostGIS layer with a date column.



I only need to show features that have the last week as a value in the date column. How to achieve this?



Unfortunately now() - 1 week doesn't seem to work










share|improve this question




















  • 2




    Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
    – markgraeflerland
    Nov 9 at 12:23










  • @markgraeflerland exactly 7 days, thought that was the definition of a week
    – Luffydude
    Nov 9 at 13:50










  • @Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
    – JGH
    Nov 9 at 14:23










  • @Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
    – markgraeflerland
    Nov 9 at 14:26










  • Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
    – Luffydude
    Nov 12 at 9:42















up vote
2
down vote

favorite












Basically I have a PostGIS layer with a date column.



I only need to show features that have the last week as a value in the date column. How to achieve this?



Unfortunately now() - 1 week doesn't seem to work










share|improve this question




















  • 2




    Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
    – markgraeflerland
    Nov 9 at 12:23










  • @markgraeflerland exactly 7 days, thought that was the definition of a week
    – Luffydude
    Nov 9 at 13:50










  • @Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
    – JGH
    Nov 9 at 14:23










  • @Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
    – markgraeflerland
    Nov 9 at 14:26










  • Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
    – Luffydude
    Nov 12 at 9:42













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Basically I have a PostGIS layer with a date column.



I only need to show features that have the last week as a value in the date column. How to achieve this?



Unfortunately now() - 1 week doesn't seem to work










share|improve this question















Basically I have a PostGIS layer with a date column.



I only need to show features that have the last week as a value in the date column. How to achieve this?



Unfortunately now() - 1 week doesn't seem to work







qgis postgis postgresql style






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 13:49

























asked Nov 9 at 11:50









Luffydude

711917




711917








  • 2




    Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
    – markgraeflerland
    Nov 9 at 12:23










  • @markgraeflerland exactly 7 days, thought that was the definition of a week
    – Luffydude
    Nov 9 at 13:50










  • @Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
    – JGH
    Nov 9 at 14:23










  • @Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
    – markgraeflerland
    Nov 9 at 14:26










  • Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
    – Luffydude
    Nov 12 at 9:42














  • 2




    Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
    – markgraeflerland
    Nov 9 at 12:23










  • @markgraeflerland exactly 7 days, thought that was the definition of a week
    – Luffydude
    Nov 9 at 13:50










  • @Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
    – JGH
    Nov 9 at 14:23










  • @Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
    – markgraeflerland
    Nov 9 at 14:26










  • Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
    – Luffydude
    Nov 12 at 9:42








2




2




Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
– markgraeflerland
Nov 9 at 12:23




Do you mean last week (somewhen between mon and sunday last week) or exactly 7 days past?
– markgraeflerland
Nov 9 at 12:23












@markgraeflerland exactly 7 days, thought that was the definition of a week
– Luffydude
Nov 9 at 13:50




@markgraeflerland exactly 7 days, thought that was the definition of a week
– Luffydude
Nov 9 at 13:50












@Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
– JGH
Nov 9 at 14:23




@Luffydude not necessarily. There are several definitions (any 7 days, Monday-Sunday, or Sunday-Saturday (and other start-end days), plus partial weeks for the 1st or last week of the year). The intended usage in terms of weeks or days is relevant ex: Monday of week 1 is "last week" from Sunday of week 2, but they are more than 7 days apart.
– JGH
Nov 9 at 14:23












@Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
– markgraeflerland
Nov 9 at 14:26




@Luffydude: If I have a feature with monday in the date column than a feature created last friday would also be a feature created last week, but not neccessarily 7 days ago. That's the reason why I try to find out what your talking about
– markgraeflerland
Nov 9 at 14:26












Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
– Luffydude
Nov 12 at 9:42




Sure guys, make sense. For the purpose of this exercise I would need something like 7 days then
– Luffydude
Nov 12 at 9:42










2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










If you want to completly filter out the records, i.e. set a filter at the layer level, you can use the Postgres function to create an interval:



"update_date" >= (CURRENT_DATE - interval '1 week')


If you want to style/label the records differently, you can use the age function to return a timespan between two dates, and the week function to extract the number of weeks.



To get result from last week, the rule filter would be:



week(age(now(),"update_date"))<=1





share|improve this answer





















  • Worked like a charm. Thanks dude
    – Luffydude
    Nov 12 at 9:46


















up vote
3
down vote













You should use



NOW() - INTERVAL '1 week'


instead of



now() - 1 week





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f302001%2fhow-to-create-a-rule-on-qgis-to-show-only-features-that-have-last-week-as-date%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote



    accepted










    If you want to completly filter out the records, i.e. set a filter at the layer level, you can use the Postgres function to create an interval:



    "update_date" >= (CURRENT_DATE - interval '1 week')


    If you want to style/label the records differently, you can use the age function to return a timespan between two dates, and the week function to extract the number of weeks.



    To get result from last week, the rule filter would be:



    week(age(now(),"update_date"))<=1





    share|improve this answer





















    • Worked like a charm. Thanks dude
      – Luffydude
      Nov 12 at 9:46















    up vote
    5
    down vote



    accepted










    If you want to completly filter out the records, i.e. set a filter at the layer level, you can use the Postgres function to create an interval:



    "update_date" >= (CURRENT_DATE - interval '1 week')


    If you want to style/label the records differently, you can use the age function to return a timespan between two dates, and the week function to extract the number of weeks.



    To get result from last week, the rule filter would be:



    week(age(now(),"update_date"))<=1





    share|improve this answer





















    • Worked like a charm. Thanks dude
      – Luffydude
      Nov 12 at 9:46













    up vote
    5
    down vote



    accepted







    up vote
    5
    down vote



    accepted






    If you want to completly filter out the records, i.e. set a filter at the layer level, you can use the Postgres function to create an interval:



    "update_date" >= (CURRENT_DATE - interval '1 week')


    If you want to style/label the records differently, you can use the age function to return a timespan between two dates, and the week function to extract the number of weeks.



    To get result from last week, the rule filter would be:



    week(age(now(),"update_date"))<=1





    share|improve this answer












    If you want to completly filter out the records, i.e. set a filter at the layer level, you can use the Postgres function to create an interval:



    "update_date" >= (CURRENT_DATE - interval '1 week')


    If you want to style/label the records differently, you can use the age function to return a timespan between two dates, and the week function to extract the number of weeks.



    To get result from last week, the rule filter would be:



    week(age(now(),"update_date"))<=1






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 9 at 12:10









    JGH

    11.4k21133




    11.4k21133












    • Worked like a charm. Thanks dude
      – Luffydude
      Nov 12 at 9:46


















    • Worked like a charm. Thanks dude
      – Luffydude
      Nov 12 at 9:46
















    Worked like a charm. Thanks dude
    – Luffydude
    Nov 12 at 9:46




    Worked like a charm. Thanks dude
    – Luffydude
    Nov 12 at 9:46












    up vote
    3
    down vote













    You should use



    NOW() - INTERVAL '1 week'


    instead of



    now() - 1 week





    share|improve this answer

























      up vote
      3
      down vote













      You should use



      NOW() - INTERVAL '1 week'


      instead of



      now() - 1 week





      share|improve this answer























        up vote
        3
        down vote










        up vote
        3
        down vote









        You should use



        NOW() - INTERVAL '1 week'


        instead of



        now() - 1 week





        share|improve this answer












        You should use



        NOW() - INTERVAL '1 week'


        instead of



        now() - 1 week






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 12:12









        Asad Abbas

        704218




        704218






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f302001%2fhow-to-create-a-rule-on-qgis-to-show-only-features-that-have-last-week-as-date%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)