Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

filter through date in mongooes

var d = new Date(),
hour = d.getHours(),
min = d.getMinutes(),
month = d.getMonth(),
year = d.getFullYear(),
sec = d.getSeconds(),
day = d.getDate();


Submission.find({
  /* First Case: Hour */
  created: { $lt: new Date(), $gt: new Date(year+','+month+','+day+','+hour+','+min+','+sec) } // Get results from start of current hour to current time.
  /* Second Case: Day */
  created: { $lt: new Date(), $gt: new Date(year+','+month+','+day) } // Get results from start of current day to current time.
  /* Third Case: Month */
  created: { $lt: new Date(), $gt: new Date(year+','+month) } // Get results from start of current month to current time.
  /* Fourth Case: Year */
  created: { $lt: new Date(), $gt: new Date(year) } // Get results from start of current year to current time.
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery datatable table header not increasing on expanding 
Javascript :: popover on show event 
Javascript :: javascript array split empty string 
Javascript :: js random number between 1 and 5 
Javascript :: how to insert an item into an array at a specific index in javascript 
Javascript :: javascript array filter 
Javascript :: reverse json.stringify 
Javascript :: flatten an array javascript 
Javascript :: use effect react 
Javascript :: liquid object 
Javascript :: installing react router dom 
Javascript :: how to login with api in react js 
Javascript :: dynamic navigation with subitems 
Javascript :: javascript send post data with ajax 
Javascript :: sort method in js 
Javascript :: momentjs 
Javascript :: onfocus js 
Javascript :: max value from array in javascript 
Javascript :: sort array of objects javascript by key value 
Javascript :: moment get month short name 
Javascript :: password meter 
Javascript :: innertext javascript 
Javascript :: how to see if checkbox is checked 
Javascript :: javaScript getDay() Method 
Javascript :: get console javascript 
Javascript :: change url link javascript 
Javascript :: react hooks vs redux 
Javascript :: separate last character string javascript 
Javascript :: javascript for loop array backwards 
Javascript :: replace in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =