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?
 

81 thoughts on “Date manipulation with moment.js

  1. Pingback: Cialis from canada
  2. Pingback: Buy viagra
  3. Pingback: Cialis canada
  4. Pingback: Buy generic viagra
  5. Pingback: Buy generic cialis
  6. Pingback: Buy cialis online
  7. Pingback: Generic cialis
  8. Pingback: Cialis coupon
  9. Pingback: Cialis prices
  10. Pingback: essayforme
  11. Pingback: Cialis coupon
  12. Pingback: Buy cialis
  13. Pingback: Cialis online
  14. Pingback: tadalafil 40 mg
  15. Pingback: cialis pills
  16. Pingback: cost cialis 20mg
  17. Pingback: tadalafil generic
  18. Pingback: cialis generic
  19. Pingback: levitra generic
  20. Pingback: sildenafil citrate
  21. Pingback: viagra 100mg
  22. Pingback: sildenafil 100mg
  23. Pingback: augmentin 875 mg
  24. Pingback: amiodarone 200 mg
  25. Pingback: lipitor generic
  26. Pingback: simvastatin 20 mg
  27. Pingback: diflucan 150 mg
  28. Pingback: levitra 20 mg
  29. Pingback: viagra pills

Leave a Reply

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