Date manipulation with moment.js

In my recent project, I have a filter as the image bellow:

Screen Shot 2015-12-25 at 11.16.17 AM

The period dropdown field have some options:

  • Today
  • Yesterday
  • Week to date
  • Last week
  • Month to date
  • Last month

and when you change the Period, the Date From and Date To should be changed with corresponding data.

For example, let’s say today is 25/12/2015. So:

  • When we choose Today, the values will be 25/12/2015
  • When we choose Yesterday, the values will be 24/12/2015
  • When we choose Week to date, the values will be 21/12/2015 and 25/12/2015 respectively
  • When we choose Last week, the values will be 14/12/2015 and 20/12/2015 respectively
  • When we choose Month to date, the values will be 01/12/2015 and 25/12/2015 respectively
  • And finally, when we choose Last month, the values will be 01/11/2015 and 30/11/2015

If you implement this function by pure Javascript you may have some difficulty such as how to get the last day of specific month, how to get the begin & end date of a week…

Fortunately, we have moment.js library which help us manipulate with datetime in Javascript very easy.

The above requirements can be done by small line of codes (in my case, I use AngularJS)

Much easier, right?

7,257 thoughts on “Date manipulation with moment.js

  1. Pingback: online gambling
  2. Pingback: slots online
  3. Pingback: online slots
  4. Pingback: real casino slots
  5. Pingback: play slots
  6. Pingback: online slot games
  7. Pingback: slot games
  8. Pingback: play slots online
  9. Pingback: free slots
  10. Pingback: slots free
  11. Pingback: caesars slots
  12. Pingback: slots free games
  13. Pingback: vegas world slots
  14. Pingback: slots lounge
  15. Pingback: pch slots
  16. Pingback: caesars free slots
  17. Pingback: house of fun slots
  18. Pingback: slots of vegas
  19. Pingback: vegas slots
  20. Pingback: free vegas slots
  21. Pingback: scatter slots
  22. Pingback: buffalo gold slots
  23. Pingback: liberty slots
  24. Pingback: free slots 777
  25. Pingback: slots games
  26. Pingback: hypercasinos
  27. Pingback: gambling sites
  28. Pingback: slot machines
  29. Pingback: casinos near me
  30. Pingback: pechanga casino
  31. Pingback: fortune bay casino
  32. Pingback: casinos in iowa
  33. Pingback: plainridge casino
  34. Pingback: royal river casino

Leave a Reply

Your email address will not be published. Required fields are marked *