Skip to content
Advertisement

Tag: date

Writing a JavaScript program to calculate a leap year

I am writing a JavaScript program that takes in a date typed by the user and determines what day of the week the given date falls on. I am able to get the program to take in the date. I have used debug statements to print the values of the day, the month, the year, and the century to make

JavaScript for getting the previous Monday

I would like for the previous Monday to appear in the field where a user enters today’s date. E.g.: If today’s date is entered 29-Jan-16 then the code would make the previous Monday’s date to appear instead (which would be 25-Jan-16). I have seen some code online: However, this is not quite working, why? Answer I think your math is

Compare date with todays date 10 years ago

I want to check if the given date is higher than 10 years ago from today (so the person would have less than 10 years). I have searched many info with no possitive result. EDIT: When I alert “objetoFechaNacimiento”, if the user entered “22/1/2015”, it alerts “Sat Oct 01 2016 00:00:00 GMT+0200”. This must be the problem… This is what

How to convert dd/mm/yyyy string into JavaScript Date object? [duplicate]

This question already has answers here: Convert dd-mm-yyyy string to date (15 answers) Closed 8 months ago. How to convert a date in format 23/10/2015 into a JavaScript Date format: Answer MM/DD/YYYY format If you have the MM/DD/YYYY format which is default for JavaScript, you can simply pass your string to Date(string) constructor. It will parse it for you. DD/MM/YYYY

MomentJS – How to get last day of previous month from date?

I’m trying to get last day of the previous month using: Where: But after using it returns date But last day of the 10’th month is 31. How can I solve i please? Many thanks for any help. Answer Simply add a endOf(‘month’) to your calls: var dateFrom = moment(dateFrom).subtract(1,’months’).endOf(‘month’).format(‘YYYY-MM-DD’); http://jsfiddle.net/r42jg/327/

Get hours difference between two dates in Moment Js

I’m able to get the difference between two dates using MomentJs as follows: However, I also want to display the hour when applicable (only when >= 60 minutes have passed). However, when I try to retrieve the duration hours using the following: it is returning the current hour and not the number of hours between the two dates. How do

Advertisement