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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:01:34+00:00 2026-06-14T22:01:34+00:00

I want to see whether an item in my array was created today, so

  • 0

I want to see whether an item in my array was created today, so I’m using an arrayFilter to filter each element in my array, the problem is, I can’t get my filter to work properly:

return ko.utils.arrayFilter(self.enquiries(), function (enquiry) {
    var include = true;

    if (self.onlyToday()) {
        var formatted = $.datepicker.formatDate("dd/mm/yy", new Date());

        include = include && +enquiry.EnquiryDate.indexOf(+formatted > -1);
    }

    return include;
});

Here is what my data looks like:

formatted: 26/11/2012
enquiry.EnquiryDate: 08/11/2012 08:46:46 

So obviously, this enquiry should be filtered as it wasn’t created today.

  • 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-14T22:01:35+00:00Added an answer on June 14, 2026 at 10:01 pm

    There are several problems here.

    1. You’re putting a string in formatted, then later using +formatted > -1. +formatted will always be NaN, which is never > -1 (it’s also never equal to -1 and never < -1).

    2. You’re setting include to true and then doing include = include && .... The part following the && will never be evaluated, because the part to the left of && is true and JavaScript (like most modern languages) short-circuits expressions.

    3. If enquiry refers to an object, +enquiry will probably be NaN unless you’ve overridden its valueOf.

    4. You’re comparing strings, which means the most significant parts of the comparison will be on the left — but your date strings are in a format where the most significant values are on the right. So for example, the string "01/01/2013" is less than the string "02/02/2012", even though of course that’s not true of the dates they represent. If you want to meaningfully compare date strings, they must have the year on the left, followed by the month, followed by the day.

    Based on your quoted enquiry.EnquiryDate string, you can do this:

    var today = $.datepicker.formatDate("yy/mm/dd", new Date());
    return ko.utils.arrayFilter(self.enquiries(), function (enquiry) {
        var parts, enqDate;
    
        parts = enquiry.EnquiryDate.split(' ')[0].split('/');
        enqDate = parts[2] + '/' + parts[1] + '/' + parts[0];
        return enqDate === today;
    });
    

    Notes on the above:

    • Note that I’m getting today’s date with the year on the left.

    • I’ve removed the self.onlyToday() bit because the filter didn’t do anything if self.onlyToday() was false. My guess is you want that check outside this filter function, and you’re either going to call this filter, or not.

    • Since enquiry.EnquiryDate is a date and time string, separated with a space, first we split it on a space, then we take the first part (the date) and split it on the /. Then we recombine that in yy/mm/dd order.

    • Now we know we can do the === on the strings to see if the enquiry date equals today.

    You could, of course, do this comparison using Date objects, but as you’d just have to parse the enquiry.EnquiryDate strings into Date objects anyway, and you only want day resolution (not millisecond resolution), using a string compare seems reasonable.

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

Sidebar

Related Questions

All I need this for is strcpy(). I want to see whether the first
I want see the source code of System.Web.Routing.RouteValueDictionary class. But Reflector can't disassemble it
I want to see the source of functions like ns_initparse(), res_search() etc. Where can
I have a <asp:Checkbox /> and I want to see whether it's checked or
I want to check to see whether something is null, e.g.: string xxx(const NotMyClass&
I want to get notified when an item in a ListBox gets clicked by
I want to dynamically construct a find command and see whether it returns anything.
What I'm trying to do here is see whether the element exists in the
I want to be able to look to see whether the page at a
Currently, I have two matrixes, and want to compare it and see whether they

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.