Задать вопрос

Как отнять от даты значение?

Массив значений
[ Thu Jan 11 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Jan 12 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Jan 13 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Jan 14 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Jan 15 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Jan 16 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Jan 17 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Jan 18 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Jan 19 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Jan 20 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Jan 21 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Jan 22 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Jan 23 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Jan 24 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Jan 25 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Jan 26 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Jan 27 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Jan 28 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Jan 29 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Jan 30 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Jan 31 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Feb 01 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Feb 02 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Feb 03 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Feb 04 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Feb 05 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Feb 06 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Feb 07 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Feb 08 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Feb 09 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Feb 10 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Feb 11 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Feb 12 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Feb 13 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Feb 14 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Feb 15 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Feb 16 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Feb 17 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Feb 18 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Mon Feb 19 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Tue Feb 20 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Wed Feb 21 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Thu Feb 22 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Fri Feb 23 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sat Feb 24 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ],
[ Sun Feb 25 2024 10:00:00 GMT+0200 (Eastern European Standard Time) ]


Как правильно из этого массива выделить только дату и отнять нужную мне дату? Уже голову сломал, но не могу понять как это реализовать.
  • Вопрос задан
  • 139 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ответы на вопрос 2
dollar
@dollar
Делай добро и бросай его в воду.
Дата в Excel на самом деле представляет из себя число. Целая часть - это количество дней, а дробная часть - это время суток (как бы в процентах). Поэтому даты можно вычитать, получая интервалы между ними. А также к датам можно прибавлять интервалы, получая новые даты. Но отнимать/прибавлять можно не только интервалы, но и обычные числа.

Условно:
сегодня + 1 ====> завтра

Поэтому оперируйте с датами, как с числами. Главное, выбрать для значения результата нужный вид (не числовой, а в виде даты).
Ответ написан
BasiC2k
@BasiC2k
.NET developer (open to job offers)
так?
function myFunction() {
  
  var dateArray = [ 'Thu Jan 11 2024 10:00:00 GMT+0200 (Eastern European Standard Time)' ,
                'Fri Jan 12 2024 10:00:00 GMT+0200 (Eastern European Standard Time)',
                'Sat Jan 13 2024 10:00:00 GMT+0200 (Eastern European Standard Time)'];

  var myUnixTime = Date.parse('2023-01-01 00:00:00'); // my date

  dateArray.map(item => {
    var unixTime = Date.parse(item); // 
    console.log(unixTime);
    var diff = unixTime - myUnixTime;
    console.log(diff); // difference in milliseconds
  });

}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы