Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:24:53+00:00 2026-06-15T13:24:53+00:00

I am getting some data from SQL which has timestamp and i Wanna check

  • 0

I am getting some data from SQL which has timestamp and i Wanna check whether they are same day or not….

In a loop i am trying to check the previous loop timestamp is same as the current loop timestamp…… I am trying something like this…..

$.each(data, function(key, value) {
   if( new Date([value.startTime] * 1000) === previousdate){
       console.log("*** Same day ***");
    }
    previousdate = new Date([value.startTime] * 1000);
}

But though they are same day but they differ in time …… I just want to check they both are same day or not….. I can trim them before comparing them so that way it works fine…. but is there any other effective way to do this…..

Cheers…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:24:54+00:00Added an answer on June 15, 2026 at 1:24 pm

    It’s not clear to me if you want to check if it’s the same day or the same date: you talk about same day but from what you’re doing seems your want to check if it’s the same date. A way to check if it’s the same date, is the follow:

    $.each(data, function(key, value) {
        var current = new Date(value.startTime * 1000).setHours(0, 0, 0, 0);
        var previous = new Date(previousDate).setHours(0, 0, 0, 0);
    
        if(current === previous){
            console.log("*** Same day ***");
        }
        previousdate = new Date([value.startTime] * 1000);
    })
    

    You basically create a new Date object, resetting all the time values (hours, minutes, seconds, and milliseconds).

    If you’re using the previousdate only for this checking, you can simplify:

    $.each(data, function(key, value) {
        var current = new Date(value.startTime * 1000).setHours(0, 0, 0, 0);
    
        if(current === previousdate){
            console.log("*** Same day ***");
        }
    
        previousdate = current;
    });
    

    Besides the * 1000 operation, that is the easiest and safest way AFAIK. You let the engine doing all the calculation: not all days are made by 24 hours – see the daylight saving time – and not all the minutes are made by 60 seconds – see the leap second; so it’s no safe make any operation assuming that.

    Of course some engine could not deals with leap second as well, for instance, but it’s still better, at least for the daylight saving time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my package I have Execute SQL Task which is getting some data from
I have to prepare a report which is getting some fields data from conf
I'm getting some data from the web service and saving it in the core
I am getting some data from my database table. The query I use is
I have some troubles with getting the data from the website. The website source
I have a rather simple web-service which exposes data from sql server. It will
We are getting some piece od data from the DB, but the method uses
I get the lastupdated date from SQL Server 2008 which has the follow value
I've just discovered (by necessity) that TSQL has some functionality to extract data from
I'm getting error Not unique table/alias while trying to display data from MySQL database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.