Filter array of dates (allow only one date entry per day)

filter array by date javascript
date range filter in javascript
date filter in javascript
algolia dates
javascript array.filter multiple arguments
moment js
filter data between two dates in javascript
filter with date and time on side

I am having a hard time figuring this out :(

I have an array of dates:

let myDatesArray = [
"Sun Oct 01 2017 05:30:00 GMT+0530 (IST)",
"Mon Oct 02 2017 05:30:00 GMT+0530 (IST)",
"Mon Oct 02 2017 06:30:00 GMT+0530 (IST)",
"Tue Oct 03 2017 05:30:00 GMT+0530 (IST)",
"Wed Oct 04 2017 05:30:00 GMT+0530 (IST)",
"Thu Oct 05 2017 05:30:00 GMT+0530 (IST)",
"Fri Oct 06 2017 05:30:00 GMT+0530 (IST)",
"Sat Oct 07 2017 05:30:00 GMT+0530 (IST)"]

However, I am only allowed to have one date entry per day! The array can have TWO dates for Monday, October 2nd but I would have to discard one (hence one per day). I tried using myDatesArray.filter(el => ????) but can't figure it out. Any ideas on how I could achieve this?

You can just compare the first 15 characters of each timestamp. The following keeps the last instance of duplicate days:

let dates = [
"Sun Oct 01 2017 05:30:00 GMT+0530 (IST)",
"Mon Oct 02 2017 05:30:00 GMT+0530 (IST)",
"Mon Oct 02 2017 06:30:00 GMT+0530 (IST)",
"Tue Oct 03 2017 05:30:00 GMT+0530 (IST)",
"Wed Oct 04 2017 05:30:00 GMT+0530 (IST)",
"Wed Oct 04 2017 06:30:00 GMT+0530 (IST)",
"Wed Oct 04 2017 07:30:00 GMT+0530 (IST)",
"Thu Oct 05 2017 05:30:00 GMT+0530 (IST)",
"Fri Oct 06 2017 05:30:00 GMT+0530 (IST)",
"Sat Oct 07 2017 05:30:00 GMT+0530 (IST)"]

let unique = dates.filter((d, i, arr) => 
  d.substr(0,15) != (arr[i+1]  || '').substr(0,15)
); 

console.log(unique)

How to Filter Data Array by Week Filter(), You can use method isBetween of moment js library with current date. These parts allow you to create a Date object from a string. toDate (localized) { return new Date( localized.year, localized.month - 1, localized.day, 0, sep) { return function (date, list) { return list.filter(item => { var itemDate = parseDate(pattern, sep,� (1) If you need to filter out the specified date range in the pivot table, please click the arrow beside Row Labels, and then click Date Filters > Before/After/Between in the drop-down list as you need. In my case I select Date Filters > Between. Now in the Date Filter (Date) dialog box, specify the certain date range, and click the OK button

You could take a Set with a substring of the date strings.

let array = ["Sun Oct 01 2017 05:30:00 GMT+0530 (IST)", "Mon Oct 02 2017 05:30:00 GMT+0530 (IST)", "Mon Oct 02 2017 06:30:00 GMT+0530 (IST)", "Tue Oct 03 2017 05:30:00 GMT+0530 (IST)", "Wed Oct 04 2017 05:30:00 GMT+0530 (IST)", "Thu Oct 05 2017 05:30:00 GMT+0530 (IST)", "Fri Oct 06 2017 05:30:00 GMT+0530 (IST)", "Sat Oct 07 2017 05:30:00 GMT+0530 (IST)"],
    seen = new Set,
    result = array.filter(s => !seen.has(s.slice(0, 15)) && seen.add(s.slice(0, 15)));

console.log(result);

Filter By Date | How to | Managing Results | Guide, You can also leverage them to filter search results on a specific date range. want to allow users to filter on recent posts, or only see posts from a Note that this attribute needs to be a numeric value for Algolia to be Now that Algolia can understand our dates, we can use the filters setRanking(Arrays. To filter data to include data based on dates, you can use the FILTER function with one of Excel's date functions. In the example shown, the formula in F5 is: = FILTER( data,MONTH( date) = 7,"No data") where "data" (B5:E15) and "date" (C5:C15) are named ranges. The result returned by FILTER includes data in the month of July only.

const singleDate = myDatesArray.reduce((acc,str) => {
  acc[new Date(str).setHours(0,0,0,0)] = str;
  return acc;
},{});

const filteredDates = Object.values(singleDate);

// ["Sun Oct 01 2017 05:30:00 GMT+0530 (IST)", "Mon Oct 02 2017 06:30:00 GMT+0530 (IST)", "Tue Oct 03 2017 05:30:00 GMT+0530 (IST)", "Wed Oct 04 2017 05:30:00 GMT+0530 (IST)", "Thu Oct 05 2017 05:30:00 GMT+0530 (IST)", "Fri Oct 06 2017 05:30:00 GMT+0530 (IST)", "Sat Oct 07 2017 05:30:00 GMT+0530 (IST)"]

Filter on array of date ranges - Open Q&A, I have booking slots for each record and I want to query all records that do The filtering with Algolia on dates will work best only if looking at a single the timestamp also allow you to get all news from 2017: "filters": "dates� Date Filters in Excel. We have a lot of options when filtering a column that contains dates. The filter drop-down menu list groups the dates by years, months, days, hours, minutes, seconds. We can expand and select those check boxes to filter multiple items. We can also choose from the Date Filters sub menus.

Using the first chars something like this should work:

let dateMap = {};
myDatesArray.forEach(d => dateMap[d.substr(0,15)] = d);
myDatesArray = Object.values(dateMap);

Using date_start and date_end with Date Filters – Looker Help Center, The following syntax works works with most dialects, but certain dialects have specific use cases. BigQuery allows fine-grain control when working with table wildcard When there is no value specified for date_filter , both {% date_start The solution is to add an extra day to the end date of the date filter,� Insert a Filter For a Specific Date Range. We will click the dropdown arrow on the Rows Label heading; We will select Field name, then Date filters, and click Between; Figure 12- Using filters. In the Between dialog box, we will type the desired start and end dates; Figure 13 – Date filters. Figure 14 – How to insert date filters into the

Use Set to level to trim array from duplicate values

// array of dates
    let myDatesArray = [
      "Sun Oct 01 2017 05:30:00 GMT+0530 (IST)",
      "Mon Oct 02 2017 05:30:00 GMT+0530 (IST)",
      "Mon Oct 02 2017 06:30:00 GMT+0530 (IST)",
      "Tue Oct 03 2017 05:30:00 GMT+0530 (IST)",
      "Wed Oct 04 2017 05:30:00 GMT+0530 (IST)",
      "Thu Oct 05 2017 05:30:00 GMT+0530 (IST)",
      "Fri Oct 06 2017 05:30:00 GMT+0530 (IST)",
      "Sat Oct 07 2017 05:30:00 GMT+0530 (IST)"
    ];

// make a Set from that array. Set automaticaly removes all duplicate values
const dateSet = new Set(myDatesArray);

// then make array out of Set.
let myDatesArrayLeveled = Array.from(dateSet);

// you now have array of unique date values
console.log(myDatesArrayLeveled);

How to Filter for Dates with VBA Macros in Excel, Includes examples for filtering for a range between two dates, date groups This allows us to filter for date ranges like before, after, or between two dates. Years (2014 and 2016) use last day of the time 'period for each array item . obtain a message who that user is, and allow him to open read only. Use a formula in column E that returns the day number then you can filter on day 1. Entered in E2 and copied down: =DAY (A2) All of your dates are already the 1st of the months (unless you did that just for demonstration purposes).

Date Range Filters, You can create filters using absolute or relative date ranges. If the input data is a one-dimensional array with two elements: And both elements are numbers,� One way is to add this calculated column to your table, which returns a 1 or 0 for latest/not latest which you can use as a filter . Is Latest Row Filter = VAR LatestDate = MAXX(FILTER('Table1','Table1'[Type] = EARLIER('Table1'[Type])),'Table1'[Date]) RETURN IF('Table1'[Date]=LatestDate,1,0)

Docs, As a start, you might have acquired moment through bower or node_modules or Note: To allow moment.js plugins to be loaded in requirejs environments, Instead of modifying the native Date.prototype , Moment.js creates a wrapper for the input string, but know it could be one of many, you can use an array of formats. filter() calls a provided callback function once for each element in an array, and constructs a new array of all the values for which callback returns a value that coerces to true. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned

spatie/opening-hours: Query and format a set of opening , It can also return arrays of opening hours for a week or a day: In the example above, data are strings but it can be any kind of value. So you can embed� In Excel, the Data Validation is a powerful function which can help you to create drop down list, to prevent duplicate entries, etc. It also can help you to prevent entering other data format but only date format in specific cells. Please do with following steps: 1. Click Data > Data Validation > Data Validation, see screenshot: 2.

Comments
  • How do you know which one for a specific day you want to discard? or does it not matter?
  • @RobG I did think about that but I thought it was a bit messy :/
  • @WalterMonecke—I added it as an answer, I think it's the most concise of the current answers. :-)
  • Agree, Set are the best way to level the array elements
  • Thank you very much!
  • This won't work across months, getDate returns just the day in the month so will treat 1 Jan and 1 Feb as duplicates. :-(
  • @RobG agreed. we can always add an extra check for the month as well.
  • You could make the key new Date(str).setHours(0,0,0,0) but the usual caveat for using the built–in parser applies. Your method also assumes the host is set to the same timezone as the timestamps (IST). :-)
  • @RobG i guess my updated solution will fix the issue.
  • It won't fix the timezone issue.
  • The OP only wants to consider the date part, not the time so one of the Mondays should be removed. Using the whole timestamp as a key doesn't do that.