'How to Count the items by checking the date within 30 days from the current date?
How do I count my items by checking the date within 30 days from the current date?
Below is the current code that I need to add for items within 30 days
<template>
<div>
<div>
<div class="tree">
<table width="100%" border="1">
<tr>
<th>row</th>
<th>Item</th>
<th>Category</th>
<th>Date</th>
<th>Description</th>
</tr>
<tr v-for="(user,index) in bookData" v-bind:key="user.listData">
<td>{{ user.index }}</td>
<td>{{ user.item_id }}</td>
<td>{{ user.category_id }}</td>
<td>{{ user.r_date }}</td>
<td>{{ user.description }}</td>
</tr>
</table>
**New Item within 30 days :**
<div>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Watch, Component } from 'vue-property-decorator';
import API from '@/API';
@Component
export default class BookTable extends Vue {
private bookData: any = [];
private tempData: any = [];
private metadata: any = JSON.stringify([], undefined, 2) ;
private created(): void {
this.getBookDetails();
if (this.currentUser) {
this.getCategories();
}
}
@Watch('categories')
private getBookDetails(): void {
if (this.categories.length > 0) {
for (const category of this.categories) {
API.Book.getBook(category.id).then((response) => {
this.bookData = this.bookData.concat(response ? response : []);
this.tempData = this.bookData;
});
}
}
}
}
</script>
Please do help as I am trying to learn more on Vue and new to it and also typescript.
Solution 1:[1]
You can use a computed property for this and hook it up to a function that calculates the days. eg
let date_1 = new Date('10/25/2021');
let date_2 = new Date();
function numOfDaysBtn(date_1, date_2) {
let difference = date_1.getTime() - date_2.getTime();
let TotalDays = Math.ceil(difference / (1000 * 3600 * 24));
return TotalDays;
}
console.log(numOfDaysBtn(date_1, date_2) + " days in between");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kwesi Smart |
