Reputation: 79
How can I calculate last day as a date in node jst?
I run the script include data of yesterday. i wanna change it.the last day of month i have issue. for example Date:1-4-2022 but the script include data of yesterday we need the file name is :Example_March
how can i define it in this code
const curMonth = new Date().toLocaleString("default", { month: "long" });
let fileName = `example_${curMonth}.xlsx`;
writeInFileAsync(html, fileName).then(() => {
sendEmail(htmlForEmail, fileName);
)}
and save the sheet its the same issue.
const convertJsonToExcel = (table, fileName) => {
var wb = XLSX.utils.table_to_book(table, {
sheet: `example_${new Date().getMonth() + 1}`,
});
XLSX.writeFile(wb, fileName, { cellStyles: true });
};
Upvotes: 3
Views: 117
Reputation: 4413
To calculate the yesterday date in javascript, you can use this helper function:
function getYesterdayDate() {
return new Date(new Date().getTime() - 24*60*60*1000);
}
Upvotes: 2