Determine the day of the month based on a given date

My calendar date is in the format "Wed Jun 05 2013 00:00:00 GMT+0100 (CET)", but I need it to be in the yyyy-mm-dd format.

Here’s what I’ve tried:

var year = mydate.getFullYear();
var month = mydate.getMonth();
var day = mydate.getDay(); 

Unfortunately, while I was able to extract the year and month, I am unable to get the day.

Answer №1

If you need to extract the day of the month number, simply use mydate.getDate().

To ensure the date is formatted as desired, follow these steps:

var year = mydate.getFullYear();
var month = ("0" + mydate.getMonth()).slice(-2);
var day = ("0" + mydate.getDate()).slice(-2); 

var formattedDate = [year, month, day].join("-");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing $(this).parent().remove() triggers a full page reload

A unique feature of my webpage is that with just a simple click of a button, users have the ability to dynamically add an endless number of forms. Each form contains fields for user input and also includes a convenient delete button. var form = " Name ...

Updating the parent controller's scope from a directive in AngularJS does not reflect changes

HTML: <div ng-app="myApp" ng-controller="Controller"> <test ng-if="toggle" props="condition"></test> </div> Javascript: var myApp = angular.module('myApp', []); myApp.controller('Controller', ['$scop ...

Tips for avoiding Blob data and GUIDs from showing up in your browser's title

Currently, my process involves creating a PDF file on our server and displaying it in the browser using javascript as shown below: file = new window.Blob([data], { type: 'application/pdf' }); var fileUrl = URL.createObjectURL(file); var wn ...

Missing index in the GET variable

I have a div with the class .excelDL. When this div is clicked, a form is submitted using AJAX without refreshing the page, and it works perfectly fine. However, the issue I am facing is that I need to check if $_GET['excel'] has been set to one ...

Is there a way to automatically convert a webpage to a PDF when it is requested?

I'm looking to convert the webpage into a PDF file upon request. Below are the scripts I am using: <script> pdfdoc.fromHTML($('#container').html(), 10, 10, { 'width': 110, ...

use react-router v4 exact prop to show both component

<Route exact path='/admin/task/create' component={ComponentA} /> <Route exact path='/admin/task/:id' component={ComponentB} /> Whenever I go to http://localhost:3000/task/123, ComponentB gets triggered. But strangely, when ...

"Enhancing user interaction with Vue.js through the stunning ripple effect on

Is there a way to customize the ripple effect from this source so that it doesn't always have to be a DIV? Here's an example: Currently, when I implement it like this: <ripple class="btn">send</ripple> It works as expected, but as ...

Is it possible to download multiple files using a single ajax call upon success of a click function?

In my file, there are 2 anchor tags with their respective href links. I am triggering both anchor tags at ajax call success. <a id="exportExcelFatturaIcon" href ="${createLink(action: 'downloadExcel', params: [fileName:excelFileName])}" hidde ...

Disable Button's Shadow when it is in an active state (clicked)

Check out the DEMO to see the button animation CSS in action. The CSS code for the button animations is as follows: .btnliner { /* CSS properties */ } /* More CSS properties */ .btnliner:hover { /* Hover effects */ } Here is the corresponding J ...

The pointerTap event is triggered 7 times when a PIXI.Sprite is clicked within a React component

Using the PIXI library in my React application to render animations, the stage is created with @inlet/react-pixi and gsap is used for tweening. During the initial launch of the app, a clickable sprite is created and an event listener "pointerTap" is added ...

Adjust the location.hash and then navigate using the Back button - Internet Explorer displays unique behavior compared to other web browsers

When updating `location.hash`, all browsers behave correctly by only changing the URL without refreshing the page. However, pressing the Back button in Internet Explorer and other browsers results in different behaviors. IE fails to update the history wit ...

If the list item is the first or second child, align the menu to the right

I've been facing some challenges with my mega menu implementation. The dropdown appears either on the left or right side based on calculations of offset.left, but it seems to behave differently across various screen resolutions. As a solution, I&apos ...

How do I send events from iOS (Swift) to JavaScript in React Native?

Currently, I am in the midst of a project where my goal is to seamlessly integrate React-Native into a native Swift application. To ensure that both sides are kept in sync with the state, I have implemented a 'message bus' - a mechanism designed ...

AngularJS does not update values properly if there is a style applied to the parent container

I'm struggling to find the best approach to handle this situation. This is how my AngularJS code looks: <span class="something" ng-hide="onsomecondition"> {{value}} </span> .something{ text-align:left; padding:10px;} Issue: The value ...

When adding new elements to an array, the IDs of all objects become identical

When running the code below: dietDay.meals.forEach((meal) => { meal.mealProducts.forEach((mealProduct) => { if ( mealProduct.product.id && this.fetchedProductIds.includes(mealProduct.p ...

Exploring the wonders of JQuery's $.each() method in combination with

My code seems to be facing an issue with the last part, where I have an array containing some data. var dArray = { 'var1': $("#var1").val(), 'var2': $("#var2").val(), 'var3': $("#var3").val(), 'var4' ...

What is the best way to create individual Menu items in a React/MUI navigation bar?

I am currently developing a navigation bar for an application, and I seem to be facing an issue with differentiating between multiple Menu/MenuItem elements. No matter what approach I take, both Menus and their respective MenuItems end up directing to the ...

Can each `InstancedBufferGeometry` instance have its own set of unique vertex colors?

Is it possible to assign different vertex colors to each instance of InstancedBufferGeometry? const xRes = 3; const yRes = 2; const numVertices = xRes * yRes; geometry = new THREE.InstancedBufferGeometry(); geometry.copy(new THREE.PlaneBufferGeometry(3, 2 ...

Extending Node.js with Pug templates

Brand new to this! Recently set up a server using node.js, but I'm encountering issues with pug views. I'm attempting to extend login.pug into index.pug, but all I'm seeing is blank content except for the footer and head. What am I doing wro ...

Does MongoDB have a method to identify the presence of an element within an array?

I am currently working on a query where I need to ensure that a specific string does not appear in an array. The schema I am using looks like this: _id: { type: String, required: true }, ... meta: { user_likes: { ...