Wants to compare the timestamp. Tried lots of ways but it is throwing an Invalid Date error. The variables startDate /endDate/testDate
returns a same timestamp format in 'DD.MM.YYYY HH:MM:ss' i.e. '21.12.2021 08:29:00'
JavaScript
x
9
1
var startDate = cy.get('[data-placeholder="Select time range (from)"]').invoke('val')
2
var endDate = cy.get('[data-placeholder="Select time range (to)"]').invoke('val')
3
var testDate = cy.get('td:nth-child(5)>span').invoke('text')
4
5
1. moment(startDate ,'DD.MM.YYYY HH:MM:ss' ).format('DD.MM.YYYY HH:MM:ss') /// returns Invalid Date
6
2. moment(startDate ,'DD.MM.YYYY HH:MM:ss' ).format('DD.MM.YYYY HH:MM:ss').valueOf() /// returns Invalid Date
7
3. moment(startDate ,'DD.MM.YYYY HH:MM:ss' ).format() /// returns Invalid Date
8
4. moment(startDate ,'DD.MM.YYYY HH:MM:ss' ) /// returns Invalid Date
9
Also tried using isBetween() function. But for all the conditions it is throwing result as false
.
JavaScript
1
4
1
cy.log( moment(testDate , 'DD.MM.YYYY HH:MM:ss').isBetween(
2
(moment(startDate,'DD.MM.YYYY HH:MM:ss')), (moment(endDate,'DD.MM.YYYY HH:MM:ss'))
3
) )
4
please correct me.
Advertisement
Answer
From https://momentjs.com/docs/#/parsing/string-format/
MM
in HH:MM:ss
should be small letters. That is, moment('21.12.2021 08:29:00', 'DD.MM.YYYY HH:mm:ss')
should work fine.