News Articles date

Is there anyway to change the placeholder style of year, month, and day separators (/) in a date input field?

I do not like the way a browser styles placeholder text for a date input field. The forward slash character(/) is in a normal black color and the year, month, and day values are a light gray. I want to make the whole thing light gray. How do I do that? Source: CSS – Stack […]

Store date as "yyyy-MM-dd" in Mongoose via Material UI DatePicker

As I’m not exactly used to work with dates on Javascript, it’s been quite hard to tackle it without asking for help, and I’ve been struggling for hours on this. My goal is to choose a date using Material UI DatePicker and store it as a string following the "yyyy-MM-dd" format. In my last attempt, […]

Compare date strings without the Date object possible?

If I define a date range using purely date strings in yyyy-mm-dd format, it appears comparision will work just fine without using the Date object: const dateParts = ‘2021-12-15–2022-01-15’.split(‘–‘) // My date range const startDate = dateParts.slice(0, 1) // ‘2021-12-15’ const endDate = dateParts.slice(1) // ‘2022-01-15’ const date = ‘2021-12-14’ // Test if date is […]

How to generate date in the format of credit/debit card expiry date?

I have a requirement of generating dates in this format ‘Thru: 12/20’ (like credit/debit card expiry date format). What is the best way of generating date in this format? new Date().toJSON().slice(0,7).split(‘-‘).reverse().join(‘/’) I got the date in mm/yyyy format but couldn’t get the desired result Source: Vue – Stack Overflow

How to get the first day of the next month in JavaScript

I need to get the first day of the next Month for a datePicker in dd/mm/yyyy format. how can i do it? i have this code : var now = new Date(); if (now.getMonth() == 11) { var current = new Date(now.getFullYear() + 1, 0, 1); } else { var current = new Date(now.getFullYear(), now.getMonth() […]

How do I get the days between the today’s day and the last day of the month using Moment.js?

Here’s the code that I have right now: const moment = require(‘moment’) const m = moment const currDay = m().format(‘D’) const dayOfWeek = m().format(‘dddd’) const daysInMonth = m().daysInMonth() const startOfMonth = moment().startOf(‘month’).format(‘YYYY-MM-DD hh:mm’); const endOfMonth = moment().endOf(‘month’).format(‘YYYY-MM-DD hh:mm’); I need to create a calendar row where the first item would be the todays date, and […]

Calculation of duration between two dates doesn’t result in expected result

This is how I simply calculate an age, by using a current date and a birthday date: const now = moment(current) const bday = moment(birthday) const diff = now.diff(bday) const { _data } = moment.duration(diff) console.log(_data); I set these values, which should be exactly one year diff… current: 2021-11-20T23:00:00.000Z birthday: 2020-11-20T23:00:00.000Z …and which results in […]

How to change a date format in JavaScript

I have a date in following format: 13 Dec,2021 12:59:58 and I want to change it into: 13-12-2021 pls suggest some fix Source: JavaSript – Stack Overflow

date-fns isSameWeek not working as expected

I’m new with date-fns but intuitively, I would expect this to be true: isSameWeek(new Date(2021, 11, 11), new Date(2021, 11, 12)) But it actually is false I must be missing something? It looks like Thursday seems to be the start of the week because this is true: isSameWeek(new Date(2021, 11, 12), new Date(2021, 11, 18)) […]

How to set a date string to a the following format

Im using javascript and trying to convert a string to a different format. I did some research on this format but no one has asked about it yet so I thought I may ask. So I have seen that others want to convert a date string which has shorter length. But this format is different. […]

Default Timezone is incorrect for only my site when running new Date();

Okay so I am deving a new React site and and playing around with some time stuff and realised that when using the dev tools and running a new Date() I get back Fri Dec 03 2021 03:55:44 GMT+0000 (Greenwich Mean Time) However since I am in the Australian Timezone I expect that this should […]

Integrate timer with PHP, Javascript and HTML

I am learning PHP on my own and I want to try to do the following: I get multiple results like this: 2021,12,01,21,00,00 using regex to get information from an external site. As you can see, it’s a date. I save that data in the variable $prueba and then do an echo p class="time hidden">’.$prueba.'</p […]

Incorrect date input being stored within state

I am getting confused with javascript dates but within my app, I am using the following npm package: rc-datepicker Here the user clicks on a date, which is 21/11/2021 but for some reason, within state, it is being stored as: 2021-11-20T23:25:43.223Z which is the day prior. I have got a console log of the date […]

How could i get the the Nth Monday,Tuesday,etc. of every month between two dates using Javascript

I have a program where an user can set an event, with an star date, end date and the period of repetition the event shall repeat, weekly, monthly by date, monthly by weekday and yearly. After the user creates the event, it gets saved on the database and the is displayed the event in a […]

Is `new Date(string)` reliable in modern browsers, assuming the input is a full ISO 8601 string?

There are many warnings out there about not using new Date(string) (or the equivalent Date.parse(string) in javascript because of browser inconsistencies. MDN has this to say: It is not recommended to use Date.parse as until ES5, parsing of strings was entirely implementation dependent. There are still many differences in how different hosts parse date strings, […]

react-hook-form defaultValues that is a date not rendering

I am quite new to react and javascript so please excuse me if this is a bit of a rudimentary question. The simplified code is below or can be seen at import React from ‘react’; import ReactDOM from ‘react-dom’; import { useForm } from "react-hook-form"; type Person = { firstname :string; lastname :string; dob […]

How to get a date that now date minus condition value? [duplicate]

I have a date picker, i want to user cannot pick a date but date now minus this date less than 18 year(i don’t want the user less than 18 years old).but i don’t know how to do that. i described my idea by this code below. const nowDate = new Date() const valueCondition = […]

Passing my payload through JSON.parse alters my date object values to not line up

Prior to using JSON.parse(), my payload contents are as follows: let payload = { "name":"bob", "timeDetails": [ { "windowName":"Window A", "windowTimes": { "startDate":"2021-11-20T20:39:46.785Z", "endDate":"2021-11-20T20:39:54.786Z" } } ] } So paying particular attention to my dates, when I then proceed to issue the following on the above payload, i.e.: let job = JSON.parse(payload); console.log(job); I am […]

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.