last 30 days record
const list = [{
id: "95",
datum: "2020-10-11",
trade: "EUR/USD BUY",
aktion: "closed",
pips: "10"
},
{
id: "94",
datum: "2020-06-09",
trade: "GBP/USD BUY",
aktion: "TP Hit",
pips: "65"
},
{
id: "93",
datum: "2020-08-01",
trade: "NZD/USD SELL",
aktion: "SL Hit",
pips: "-57"
},
]
const currentDate = new Date();
const currentDateTime = currentDate.getTime();
const last30DaysDate = new Date(currentDate.setDate(currentDate.getDate() - 30));
const last30DaysDateTime = last30DaysDate.getTime();
const last30DaysList = list.filter(x => {
const elementDateTime = new Date(x.datum).getTime();
if (elementDateTime <= currentDateTime && elementDateTime > last30DaysDateTime) {
return true;
}
return false
}).sort((a, b) => {
return new Date(b.datum) - new Date(a.datum);
});
console.log(last30DaysList)
-------------------------------------------------------------------------------------------------------------------------------
lastSynced > new Date().setDate(new Date().getDate() - 1)
array.push
categoryList = []
Array.prototype.push.apply(categoryList, categories)
import {unionBy, uniqBy} from 'lodash';
categoryList = uniqBy(categoryList, 'categoryId')
if (dateFrom) queryFilter.dateFrom = {
$gte: new Date(dateFrom).getTime(), $lt: new Date(new Date(dateFrom).setDate(new Date(dateFrom).getDate() + 1)).getTime()
}
if (dateTo) queryFilter.dateTo = {
$gte: new Date(dateTo).getTime(), $lt: new Date(new Date(dateTo).setDate(new Date(dateTo).getDate() + 1)).getTime()
}
dateFrom = '2020/12/01'
dateTo = '2021/12/01'
/* get all date array with range/*
Array(Math.floor((Number(new Date(dateTo)) - Number(new Date(dateFrom))) / 86400000) + 1)
.fill("")
.map((_, idx) => (new Date(new Date(dateFrom).getTime() + idx * 86400000)))
/* get max or latest from array object/*
[{time:12},{time:34}, {time:1}, {time:100}].sort((a: any, b: any) => parseFloat(b.time) - parseFloat(a.time))
/* get last 30 day ago date /*
moment(new Date().setDate(new Date().getDate() - 30)).format('YYYY-MM-DD')
/* get total of value of key of object in array /*
[{amount:1},{amount:10}, {amount:30}].reduce((previews: any, current: any) => previews + current.amount, 0);
<br/>
ref= https://stackoverflow.com/questions/63314206/get-the-last-30-days-from-an-array-with-dates
0 Comments