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: biaxin generic
  2. Pingback: biaxin antibiotic
  3. Pingback: biaxin coupon
  4. Pingback: biaxin coupons
  5. Pingback: fluoxetine hcl
  6. Pingback: fluoxetine 20 mg
  7. Pingback: prozac generic
  8. Pingback: prozac medication
  9. Pingback: fluoxetine 10 mg
  10. Pingback: alprostadil
  11. Pingback: alprostadil price
  12. Pingback: buy cialis
  13. Pingback: cialis oral jelly
  14. Pingback: buy viagra
  15. Pingback: viagra
  16. Hi there! [url=http://cialissmx.com/]buy cialis pills[/url] [url=http://propeciausfinasteridhq.com/]buy propecia online[/url] [url=http://cialissmx.com/]cialis 5 mg 28 compresse costo[/url] great internet site

  17. Hi! [url=http://cialissmx.com/]buy cialis[/url] [url=http://propeciausfinasteridhq.com/]order propecia[/url] [url=http://cialissmx.com/]safe reliable cialis website[/url] beneficial website

  18. Howdy! [url=http://cialissmx.com/]cialis cheap[/url] [url=http://propeciausfinasteridhq.com/]order propecia[/url] [url=http://cialissmx.com/]where to buy cialis in mexico[/url] beneficial internet site

  19. Hi! [url=http://cialissmx.com/]tadalafil[/url] [url=http://propeciausfinasteridhq.com/]where buy propecia[/url] [url=http://cialissmx.com/]cialis generico farmacia italiana[/url] very good internet site

  20. Hi there! [url=http://cialissmx.com/]buy cialis pills[/url] [url=http://propeciausfinasteridhq.com/]buy finasteride no prescription[/url] [url=http://cialissmx.com/]cialis ohne rezept deutschland[/url] good web site

  21. [url=http://lisinoprilwithoutprescription.science/]lisinopril prescription[/url] [url=http://baclofen.us.com/]Baclofen[/url] [url=http://lisinoprilgenericonline.com/]source[/url] [url=http://ventolingenericbuy.com/]Ventolin[/url] [url=http://flagylbest.us.org/]flagyl 250mg[/url]

Leave a Reply

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