Similar Question:
How to fetch the first and last day of the week in JavaScript
Is there a way to retrieve the start date and end date of the previous week by providing today's date as input to a function?
Similar Question:
How to fetch the first and last day of the week in JavaScript
Is there a way to retrieve the start date and end date of the previous week by providing today's date as input to a function?
Check out the code snippet below! Hopefully, it provides assistance to those in need!
var d = new Date();
var to = d.setTime(d.getTime() - (d.getDay() ? d.getDay() : 7) * 24 * 60 * 60 * 1000);
var from = d.setTime(d.getTime() - 6 * 24 * 60 * 60 * 1000);
alert(to);
alert(from);
If you need help with date calculations, try utilizing the Date.js library.
Date.today().previous().monday()
This could potentially be a solution for your needs.
Retrieve the final day of the month:
/**
* Allows for zero, one, or two parameters.
* If no parameters provided: defaults to today's date
* If one parameter provided: Date object
* If two parameters provided: year, (zero-based) month
*/
function fetchLastDay() {
var year, month;
var lastDay = new Date();
if (arguments.length == 1) {
lastDay = arguments[0];
} else if (arguments.length > 0) {
lastDay.setYear(arguments[0]);
lastDay.setMonth(arguments[1]);
}
lastDay.setMonth(lastDay.getMonth() + 1);
lastDay.setDate(0);
return lastDay;
}
Retrieve the final Monday:
/**
* Accepts same parameters as fetchLastDay()
*/
function fetchLastMonday() {
var lastMonday = fetchLastDay.apply(this, arguments);
lastMonday.setDate(lastMonday.getDate() - (lastMonday.getDay() == 0 ? 6 : (lastMonday.getDay() - 1)));
return lastMonday;
}
To carry out your tasks, you can do
/**
* Requires one parameter: Date object.
* Assumes the start of the week is Sunday.
*/
function getWeek(d) {
var jan1 = new Date(d.getFullYear(), 0, 1);
return Math.ceil((((d - jan1) / (24 * 60 * 60 * 1000)) + jan1.getDay() + 1) / 7);
}
and then implement
// Retrieve the final week of this month:
var lastWeekThisMonth = getWeek(fetchLastDay());
Alert("lastWeekThisMonth: %s", lastWeekThisMonth);
I recently developed a custom directive using AngularJS that contains a child directive. The child directive's main task is to create various dynamic input elements like textboxes, radio buttons, and checkboxes, each with default values sourced from a ...
In my code, I have a Select that allows me to choose the number of a chapter I want to display (see image): <select name="select" onchange="javascript:sliders[0].goTo(value);"> <?php for($i=1; $i<$row['nbChapitre']+1; $i++){ ?> ...
Novice query: I am facing an issue with a simple input type=text element linked to ng-model="xyz.zyx", where xyz refers to an object. In my controller, I initialize this object and set the value for the property zyx as shown below: xyz { zyx: $scope.zz ...
I am currently in the process of creating my website as a graphic designer. My unique touch is having the navigation positioned on top of an image (which is animated via flash). This setup is featured prominently on my homepage, which is designed with mini ...
I have a straightforward question: How can I retrieve the number of video views using the YouTube API? Although the task is simple, I need to perform this query on a large number of videos frequently. Is there a way to access their YouTube API in order to ...
I have inserted the <b-form-checkbox> element into a <b-table>: https://jsfiddle.net/fmattioni/L269rd7s/ This is my current objective: 1 - Initially, all checkboxes in the table are checked using checked="true". 2 - Try unchecking ...
I'm having trouble sending arrays and data to a page as they are not being posted. I tried using print_r($_POST); but it only shows Array() output and the other data is not getting posted. Here is the script: <script type="text/javascript"> $ ...
In my quest to create a high-speed React.js application that functions as a game, I find myself in need of displaying real-time data. However, the traditional method of loading this data from the server using Ajax doesn't quite align with the reactive ...
I am attempting to integrate my custom vis component into the MainView VerticalLayout. However, it is appearing above the layout and the layout itself contains an empty component tag. Custom component code In this section, I have labeled my component as " ...
Struggling to iterate over the location array and map it? Despite several attempts, handling the null object within the array seems challenging. What am I missing here? While using a for loop resolves the issue, the map function is proving to be a roadbloc ...
My current dilemma revolves around a document (referred to as 'root') which contains an array of other documents ('stick'), each of which in turn contain another array of documents ('leaf'). Simply put: root{ stickChain[leaves ...
Seeking a way to focus on an input field when specific keys are entered. The desired input is nested within autocomplete-vue component. Here's where it's defined: <autocomplete v-shortkey="['alt', 's']" ...
I am currently working on creating a unique calendar display that showcases all the weekdays and events, regardless of the specific day in a month. The dates extracted from the database may seem "random", but in my C# code, I have devised a method to map e ...
Is it possible for MongoDB to save an object with another object as its 'prototype' in the same schema? For example: Assume we have this object in the database: { name : 'foo', lastName : 'bar', email : '<a hre ...
When running my app built with ionic1 on iOS 11, I encountered a peculiar issue. The <select> tag dropdown list would appear in a native window, but none of the events were fired after the user selected an option. There seemed to be no way to properl ...
I am sending a canvas image to my server via AJAX using the following method: myCanvas.toBlob( function( blob ) { var fdata = new FormData( ); fdata.append( 'myFile', blob ); $.ajax( { url: 'http://myScript.foo', ...
While running the Application, I encountered an error in the declaration of constants.ts file where I was assigning data from a json file to constant variables. In the json file named object.json, I had some data structured like this: { "furniture": { ...
After creating my custom function to fetch data from an API in order to change the user's pace, I defined the changePace function with a parameter named "pace". This parameter will be determined based on the user's selection of one of four paces: ...
I am curious about the best approach to handling a response that contains various types of objects presented like this: [ {"nodeClass":"Entity", "text":"foo","entityfield":"booz"}, {"nodeClass":"User","username":"bar","userfield":"baz"} ] Each type of ob ...
After spending some time working on a customized dropdown with the use of CSS and Vanilla JavaScript (Plain JS), I encountered an issue while trying to select and update the dropdown text upon clicking an option: window.onload = () => { let [...opt ...