Filter list data by dates in angular 4





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have one list that contains birthdate of user. I want to display list of users whose birthday is one from now.



i want to display list of users whose birthdays are in one week from today.



My list is like



`<nb-list-item *ngFor="let yuvak of yuvaklist | slice:startDate:endDate ">
{{yuvak.dateofbirth}}
{{yuvak.firstname}} + + {{yuvak.lastname}}
</nb-list-item>`









share|improve this question































    0















    I have one list that contains birthdate of user. I want to display list of users whose birthday is one from now.



    i want to display list of users whose birthdays are in one week from today.



    My list is like



    `<nb-list-item *ngFor="let yuvak of yuvaklist | slice:startDate:endDate ">
    {{yuvak.dateofbirth}}
    {{yuvak.firstname}} + + {{yuvak.lastname}}
    </nb-list-item>`









    share|improve this question



























      0












      0








      0








      I have one list that contains birthdate of user. I want to display list of users whose birthday is one from now.



      i want to display list of users whose birthdays are in one week from today.



      My list is like



      `<nb-list-item *ngFor="let yuvak of yuvaklist | slice:startDate:endDate ">
      {{yuvak.dateofbirth}}
      {{yuvak.firstname}} + + {{yuvak.lastname}}
      </nb-list-item>`









      share|improve this question
















      I have one list that contains birthdate of user. I want to display list of users whose birthday is one from now.



      i want to display list of users whose birthdays are in one week from today.



      My list is like



      `<nb-list-item *ngFor="let yuvak of yuvaklist | slice:startDate:endDate ">
      {{yuvak.dateofbirth}}
      {{yuvak.firstname}} + + {{yuvak.lastname}}
      </nb-list-item>`






      angular angular-pipe






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 1:22







      Tanmay Parmar

















      asked Nov 26 '18 at 22:22









      Tanmay ParmarTanmay Parmar

      79111




      79111
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Agree with @incNick Code, But that should we wrapped inside Pipe. You can create Angular pipe filter like this.



          import { Pipe, PipeTransform } from '@angular/core';



          @Pipe({
          name: 'birthdayFilter',
          pure: false
          })

          export class FilterPipe implements PipeTransform {
          transform(items: any, args: any): any {
          return items.filter(item => this.isBirthdayInaWeek(item.birthday));
          }

          isBirthdayInaWeek(birthday){
          let weekSec = 7 * 24 * 60 * 60 * 1000;
          let today = new Date();
          let birthday = new Date(birthday);
          birthday.setFullYear(today.getFullYear());
          if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
          return true;
          } else {
          return false;
          }
          }
          }


          Template:



          <nb-list-item *ngFor="let yuvak of yuvaklist | birthdayFilter ">
          {{yuvak.dateofbirth}}
          {{yuvak.firstname}} + + {{yuvak.lastname}}
          </nb-list-item>





          share|improve this answer
























          • my date is in dd/mm/yyyy. It is not working.

            – Tanmay Parmar
            Nov 28 '18 at 2:51











          • You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

            – Suresh Kumar Ariya
            Nov 28 '18 at 4:43











          • I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

            – Tanmay Parmar
            Nov 28 '18 at 16:15













          • here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

            – Tanmay Parmar
            Nov 28 '18 at 16:17





















          0














          Simple example below:



          let weekSec = 7 * 24 * 60 * 60 * 1000;
          let today = new Date();
          let birthday = new Date('1995-11-22');
          birthday.setFullYear(today.getFullYear());
          if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
          console.log('Happy birthday');
          } else {
          console.log('...');
          }





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53490012%2ffilter-list-data-by-dates-in-angular-4%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









            0














            Agree with @incNick Code, But that should we wrapped inside Pipe. You can create Angular pipe filter like this.



            import { Pipe, PipeTransform } from '@angular/core';



            @Pipe({
            name: 'birthdayFilter',
            pure: false
            })

            export class FilterPipe implements PipeTransform {
            transform(items: any, args: any): any {
            return items.filter(item => this.isBirthdayInaWeek(item.birthday));
            }

            isBirthdayInaWeek(birthday){
            let weekSec = 7 * 24 * 60 * 60 * 1000;
            let today = new Date();
            let birthday = new Date(birthday);
            birthday.setFullYear(today.getFullYear());
            if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
            return true;
            } else {
            return false;
            }
            }
            }


            Template:



            <nb-list-item *ngFor="let yuvak of yuvaklist | birthdayFilter ">
            {{yuvak.dateofbirth}}
            {{yuvak.firstname}} + + {{yuvak.lastname}}
            </nb-list-item>





            share|improve this answer
























            • my date is in dd/mm/yyyy. It is not working.

              – Tanmay Parmar
              Nov 28 '18 at 2:51











            • You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

              – Suresh Kumar Ariya
              Nov 28 '18 at 4:43











            • I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

              – Tanmay Parmar
              Nov 28 '18 at 16:15













            • here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

              – Tanmay Parmar
              Nov 28 '18 at 16:17


















            0














            Agree with @incNick Code, But that should we wrapped inside Pipe. You can create Angular pipe filter like this.



            import { Pipe, PipeTransform } from '@angular/core';



            @Pipe({
            name: 'birthdayFilter',
            pure: false
            })

            export class FilterPipe implements PipeTransform {
            transform(items: any, args: any): any {
            return items.filter(item => this.isBirthdayInaWeek(item.birthday));
            }

            isBirthdayInaWeek(birthday){
            let weekSec = 7 * 24 * 60 * 60 * 1000;
            let today = new Date();
            let birthday = new Date(birthday);
            birthday.setFullYear(today.getFullYear());
            if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
            return true;
            } else {
            return false;
            }
            }
            }


            Template:



            <nb-list-item *ngFor="let yuvak of yuvaklist | birthdayFilter ">
            {{yuvak.dateofbirth}}
            {{yuvak.firstname}} + + {{yuvak.lastname}}
            </nb-list-item>





            share|improve this answer
























            • my date is in dd/mm/yyyy. It is not working.

              – Tanmay Parmar
              Nov 28 '18 at 2:51











            • You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

              – Suresh Kumar Ariya
              Nov 28 '18 at 4:43











            • I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

              – Tanmay Parmar
              Nov 28 '18 at 16:15













            • here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

              – Tanmay Parmar
              Nov 28 '18 at 16:17
















            0












            0








            0







            Agree with @incNick Code, But that should we wrapped inside Pipe. You can create Angular pipe filter like this.



            import { Pipe, PipeTransform } from '@angular/core';



            @Pipe({
            name: 'birthdayFilter',
            pure: false
            })

            export class FilterPipe implements PipeTransform {
            transform(items: any, args: any): any {
            return items.filter(item => this.isBirthdayInaWeek(item.birthday));
            }

            isBirthdayInaWeek(birthday){
            let weekSec = 7 * 24 * 60 * 60 * 1000;
            let today = new Date();
            let birthday = new Date(birthday);
            birthday.setFullYear(today.getFullYear());
            if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
            return true;
            } else {
            return false;
            }
            }
            }


            Template:



            <nb-list-item *ngFor="let yuvak of yuvaklist | birthdayFilter ">
            {{yuvak.dateofbirth}}
            {{yuvak.firstname}} + + {{yuvak.lastname}}
            </nb-list-item>





            share|improve this answer













            Agree with @incNick Code, But that should we wrapped inside Pipe. You can create Angular pipe filter like this.



            import { Pipe, PipeTransform } from '@angular/core';



            @Pipe({
            name: 'birthdayFilter',
            pure: false
            })

            export class FilterPipe implements PipeTransform {
            transform(items: any, args: any): any {
            return items.filter(item => this.isBirthdayInaWeek(item.birthday));
            }

            isBirthdayInaWeek(birthday){
            let weekSec = 7 * 24 * 60 * 60 * 1000;
            let today = new Date();
            let birthday = new Date(birthday);
            birthday.setFullYear(today.getFullYear());
            if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
            return true;
            } else {
            return false;
            }
            }
            }


            Template:



            <nb-list-item *ngFor="let yuvak of yuvaklist | birthdayFilter ">
            {{yuvak.dateofbirth}}
            {{yuvak.firstname}} + + {{yuvak.lastname}}
            </nb-list-item>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 27 '18 at 2:53









            Suresh Kumar AriyaSuresh Kumar Ariya

            4,9031217




            4,9031217













            • my date is in dd/mm/yyyy. It is not working.

              – Tanmay Parmar
              Nov 28 '18 at 2:51











            • You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

              – Suresh Kumar Ariya
              Nov 28 '18 at 4:43











            • I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

              – Tanmay Parmar
              Nov 28 '18 at 16:15













            • here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

              – Tanmay Parmar
              Nov 28 '18 at 16:17





















            • my date is in dd/mm/yyyy. It is not working.

              – Tanmay Parmar
              Nov 28 '18 at 2:51











            • You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

              – Suresh Kumar Ariya
              Nov 28 '18 at 4:43











            • I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

              – Tanmay Parmar
              Nov 28 '18 at 16:15













            • here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

              – Tanmay Parmar
              Nov 28 '18 at 16:17



















            my date is in dd/mm/yyyy. It is not working.

            – Tanmay Parmar
            Nov 28 '18 at 2:51





            my date is in dd/mm/yyyy. It is not working.

            – Tanmay Parmar
            Nov 28 '18 at 2:51













            You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

            – Suresh Kumar Ariya
            Nov 28 '18 at 4:43





            You need to convert to valid format, like this. var from = 'dd/mm/yyyy'.split("/") var f = new Date(from[2], from[1] - 1, from[0])

            – Suresh Kumar Ariya
            Nov 28 '18 at 4:43













            I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

            – Tanmay Parmar
            Nov 28 '18 at 16:15







            I converted into valid format. however, it still return false. isBirthdayInaWeek(dateofbirth) { let weekSec = 7 * 24 * 60 * 60 * 1000; let today = new Date(); let dateParts = dateofbirth.split("/"); let newbirthday = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]); newbirthday.setFullYear(today.getFullYear()); if ( newbirthday.getTime() <= today.getTime() || newbirthday.getTime() + weekSec >= today.getTime() ) { console.log(true); return true; } else { console.log(false); return false; } }

            – Tanmay Parmar
            Nov 28 '18 at 16:15















            here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

            – Tanmay Parmar
            Nov 28 '18 at 16:17







            here i put OR(||) condition instead of AND(&&). it shows me all the data. I guess something is wrong with getTime() method. Maybe it is not suited in my case.

            – Tanmay Parmar
            Nov 28 '18 at 16:17















            0














            Simple example below:



            let weekSec = 7 * 24 * 60 * 60 * 1000;
            let today = new Date();
            let birthday = new Date('1995-11-22');
            birthday.setFullYear(today.getFullYear());
            if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
            console.log('Happy birthday');
            } else {
            console.log('...');
            }





            share|improve this answer




























              0














              Simple example below:



              let weekSec = 7 * 24 * 60 * 60 * 1000;
              let today = new Date();
              let birthday = new Date('1995-11-22');
              birthday.setFullYear(today.getFullYear());
              if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
              console.log('Happy birthday');
              } else {
              console.log('...');
              }





              share|improve this answer


























                0












                0








                0







                Simple example below:



                let weekSec = 7 * 24 * 60 * 60 * 1000;
                let today = new Date();
                let birthday = new Date('1995-11-22');
                birthday.setFullYear(today.getFullYear());
                if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
                console.log('Happy birthday');
                } else {
                console.log('...');
                }





                share|improve this answer













                Simple example below:



                let weekSec = 7 * 24 * 60 * 60 * 1000;
                let today = new Date();
                let birthday = new Date('1995-11-22');
                birthday.setFullYear(today.getFullYear());
                if (birthday.getTime() < today.getTime() && birthday.getTime() + weekSec > today.getTime()) {
                console.log('Happy birthday');
                } else {
                console.log('...');
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 2:45









                Nick WangNick Wang

                54926




                54926






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53490012%2ffilter-list-data-by-dates-in-angular-4%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

                    Tonle Sap (See)

                    I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                    Guatemaltekische Davis-Cup-Mannschaft