Mongoose query between Start Date and End Date of a given collection

TBE

I have the following collection:

db.sponsoreds.insert([
{
    _id: 1,
    bannerPath: "dms1.jpg",
    startDate: new Date("December 12, 2015 12:00:00"),
    endDate: new Date("November 13, 2016 00:00:00")
},
{
    _id: 2,
    bannerPath: "dms2.jpg",
    startDate: new Date("January 12, 2015 12:00:00"),
    endDate: new Date("January 13, 2016 00:00:00")
},
{
    _id: 3,
    bannerPath: "dms3.jpg",
    startDate: new Date("November 12, 2017 12:00:00"),
    endDate: new Date("November 13, 2018 00:00:00")
 },
 {
 _id: 4,
 bannerPath: "grs1.jpg",
 startDate: new Date("February 01, 2016 12:00:00"),
 endDate: new Date("February 28, 2016 00:00:00")
}
])

How do i query for documents that today is between their start and end dates?

EDIT: This is not a duplication to the suggested "already-asked-question" since:

I'm asking about whether Today is between 2 dates in the document and not whether a date in the document is between 2 dates.

Ralph Shillington
db.sponsoreds.find({$and:[{startDate:{$lte:new Date()}},{endDate:{$gte:new Date()}}]})

Will return

{
        "_id" : 1,
        "bannerPath" : "dms1.jpg",
        "startDate" : ISODate("2015-12-12T17:00:00Z"),
        "endDate" : ISODate("2016-11-13T05:00:00Z")
}

when run today at 2016-02-01T10:01:41.539Z

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

get monthwise working days between a given start date and end date

Calculate days in between given start date and end date in php

Date difference between end date to start date

Improve SQL query to find range between start and end date

How to query date between in Mongoose

start date and end date between two dates

Query to see if records start_date and end_date fall in between date range

Create column of start date and end date from given date record

Given start date and end date, reshape/expand data for each day between (each day on a row)

How to add missing data entries in an array between a given start date and end date

Split Start and end date using Given Dates

Expected payments by day given start and end date

How to count total time from start date and end date in mongoose?

Mysql Query Between two colum with start_date and end_date

T-SQL Query only invoices between Start Date and End Date

MS SQL Server QUERY SUM of each item between start date and end date

How to query to return data range between start_date and end_date?

How to show date between start date and end date in ms access

Count entities by date that fall between start date and end date (postgres)

pandas: make a date histogram, given a start and end date?

Get dates given a start date an end date and day of week

get the end date base from the given start date

Days count across the months with given start date and end date

calculate start date and end date from given quarter SQL

Given number of days and date then find the start or end date in python

Get start_date and end_date for a given pattern in a dataframe

Generate start date, end date and week numbers belong to given start and end date

Split days between 2 given dates into specific batch size and get the start and end_date accordingly

How do I select the hours difference between the min start and max end of a given date period?

TOP Ranking

HotTag

Archive