Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
Javascript check if date fits in last 24 hours

I have a date time in javascript given in format dd.MM.yyyy HH.mm.

What I need to check is whether this date fits in last 24 hours or not.

Example: If date and time now is 06.04.2017 18:26 (dd.MM.yyyy HH.mm) then minimal date allowed to enter is 05.04.2017 18:26. Is it possible to do this check with javascript?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Use the Date object to do what you want - construct a Date object for each date, then compare them using the >, <, <= or >=.

Use of comparison ( ==, !=, ===, and !== ) requires you use date.getTime() as in:

var date1 = new Date();
var date2 = new Date(date1);

var same = date1.getTime() === date2.getTime();
var notSame = date1.getTime() !== date2.getTime();
console.log(same,notSame);

var date1 = new Date('06.04.2017 18:26');
var date2 = new Date('05.04.2017 18:26');

var isGreaterorEq = date1.getTime() >= date2.getTime();
var lessThan = date2.getTime() < date1.getTime();
console.log(isGreaterorEq ,lessThan );

As for the 24 hours thing:

var date1 = new Date('05.06.2017 01:26');
var timeStamp = Math.round(new Date().getTime() / 1000);
var timeStampYesterday = timeStamp - (24 * 3600);
var is24 = date1 >= new Date(timeStampYesterday*1000).getTime();
console.log(is24,timeStamp,date1,timeStampYesterday );

about 4 years ago · Santiago Trujillo Report

0

First you have convert your date to time stamp. Then you have to do this calculation time stamp(now)-86400 you get the time stamp before 24hrs let us call the variable before_24 Then check your date time stamp if it is > before_24 or no.

about 4 years ago · Santiago Trujillo Report

0

Yes you can check it with the if condition

if (parseInt(date_variable_data) > parseInt(second_date_variable_data))
{
//do action
}else
{
//do action
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!