Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  168] [ 5]  / answers: 1 / hits: 23545  / 11 Years ago, wed, november 6, 2013, 12:00:00

I need to get a past date with moment.js (http://momentjs.com/) which I receive in specific format:



moment('31.10.2013', 'dd.mm.yy');


That returns me a strange response where I see a current date in _d option:



// returns
_a: Array[7]
_d: Wed Nov 06 2013 00:10:00 GMT+0200 (EET)
_f: dd.mm.yy
_i: 26.10.2013
_isUTC: false
_l: undefined
_pf: Object
_strict: undefined


I assume that is the problem when I do formatting:



moment('31.10.2013', 'dd.mm.yy').format('YYYY/MM/DD');
// returns current date (why??!)
// 2013/11/06


So what is wrong here, could I format the past date?


More From » date

 Answers
55

At first I thought it was the format, but it was actually the format in, lower case means something different than uppercase both in and out.



moment('31.10.2013', 'DD.MM.YYYY').format('YYYY/MM/DD')
>> 2013/10/31

moment('31.10.2013', 'dd.mm.yyyy').format('YYYY/MM/DD')
>> 2013/11/06


So fix your input mask, not the format.


[#74478] Tuesday, November 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynnb

Total Points: 402
Total Questions: 96
Total Answers: 109

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
kaitlynnb questions
;