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 7050917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:12:07+00:00 2026-05-28T03:12:07+00:00

I have data something like this in mongodb { _id : ObjectId(4f0ee7310b09f7a254000001), createdAt :

  • 0

I have data something like this in mongodb

{ "_id" : ObjectId("4f0ee7310b09f7a254000001"), "createdAt" : ISODate("2012-01-12T23:58:28Z") }
{ "_id" : ObjectId("4f0ee7350b09f7a254000002"), "createdAt" : ISODate("2012-01-12T23:58:28Z") }
{ "_id" : ObjectId("4f0ee855e63cecb654000001"), "createdAt" : ISODate("2012-01-13T00:03:59Z") }
{ "_id" : ObjectId("4f0ee859e63cecb654000002"), "createdAt" : ISODate("2012-01-13T00:04:08Z") }
{ "_id" : ObjectId("4f0ee97c212d70bc54000001"), "createdAt" : ISODate("2012-01-13T00:08:54Z") }
{ "_id" : ObjectId("4f0ee99f212d70bc54000002"), "createdAt" : ISODate("2012-01-13T00:09:27Z") }

I want to show only the record based on date. Check my code its returning me nothing

//dateStr = '120112' or '120113'
var year = '20' + dateStr.substring(0,2);
var month =  dateStr.substring(2,4);
var day =  dateStr.substring(4);
dateStr = new Date(year,month,day,0,0,0);

var nextDate = new Date(year,month,day,23,59,59);

GPSData.find({"createdAt" : { $gte : dateStr, $lte:  nextDate }}, function(err, data) {
    if(err)
        console.log(err); 

    res.writeHead(200, {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*"
    });
    var body = JSON.stringify(data);
    res.end(body);  //no output here just []
});

but on mongo shell using this command I am getting results for date ‘120112’

db.gpsdatas.find({"createdAt" : {new ISODate("2012-01-12T00:00:00Z"), $lte: new ISODate("2012-01-12T23:59:59Z") }});
  • 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-05-28T03:12:07+00:00Added an answer on May 28, 2026 at 3:12 am

    Your problem is your understanding of the Date class. I’m assuming you’re trying to create a date object for the 12th of January but new Date(2012, 1, 12) is actually the 11th or 12th of February depending on local timezone. As such your code doesn’t perform the query you’re doing in the shell.

    Read up on details here http://www.w3schools.com/jsref/jsref_obj_date.asp

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

Sidebar

Related Questions

I have some data that looks something like this... +----------+----------+----------+ | Column 1 |
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I have data that always looks something like this: alt text http://michaelfogleman.com/static/images/chart.png I need
I have a query that sums and aggregates alot of data something like this:
I have data something like this: Id | Customer | CartTotal ------------------------------- 1 |
I have a data model something like this: # columns include collection_item_id, collection_id, item_id,
I have my table schema and data something like this CompanyCategoryId SubCategoryId CategoryId CompanyId
In MySQL I have one particular cell with data something like this 5,6,7,8,9 If
I have a table of data something like this. date, amount, price 2009-10-12, 20,
I have some data in MongoDB that looks like this: { name: Steve, location:

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.