Skip to content
the poor coder

javascript today minus 1 day

Poor Man
Published
Reading time
1 min read
JavaScript
// Get the current date 
var today = new Date(); 

// Subtract 1 day
today.setDate(today.getDate() - 1);

// Log the new date
console.log(today); 

This code will get the current date (today) and subtract 1 day from it. It does this by creating a new Date object (which will always return the current date) and then using the setDate() method to subtract 1 day from it. The Date object also has a getDate() method which can be used to get the day of the month that the Date object represents. It then logs the new date to the console, which will display the date from 1 day ago. It is important to note that when you subtract 1 day from the Date object, it will always return the same time of day (midnight) so if you subtract 1 day from a Date object that is not midnight, it will return the same day at midnight. Additionally, if you want to subtract more than 1 day from the Date object, you can just increase the number passed to the setDate() method. For example, if you wanted to subtract 2 days, you could use today.setDate(today.getDate() - 2);

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC