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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:22:48+00:00 2026-06-10T00:22:48+00:00

I am trying to make the situation like this: user can either fill in

  • 0

I am trying to make the situation like this: user can either fill in “just txtComStartDate” or “just txtComEndDate” or “both txtComStartDate & txtComEndDate”.

If user fill in txtComStartDate as 18/08/12, only the data from 18/08/12 onwards will display.

If user fill in txtComEndDate as 19/08/12, only the data before 19/08/12 onwards will display.

If user limit both txtComStartDate 18/08/12 and txtComEndDate 19/08/12, the data between these two dates will display.

The if statement is giving me error and not working properly. I am confused about the && and ||. Could someone help? You help would be much appreciated. Thank you.

My code:

private void searchComByDate()
{

    // Process the list of files found in the directory. 
    string[] fileEntries = Directory.GetFiles(sourceDir);
    foreach (string fileName in fileEntries)
    {
        XmlDocument xmlDoc = new XmlDocument(); //* create an xml document object.

        string docPath = fileName;

        xmlDoc.Load(docPath); //* load the XML document from the specified file.

        XmlNodeList nodeList = xmlDoc.GetElementsByTagName("item");

        foreach (XmlNode node in nodeList)
        {

            XmlElement itemElement = (XmlElement)node;

            string itemDate = itemElement.GetElementsByTagName("pubDate")[0].InnerText;
            CultureInfo provider = CultureInfo.InvariantCulture;
            if (txtComStartDate.Text != (String.Empty) && DateTime.Parse(itemDate) >= DateTime.ParseExact(txtComStartDate.Text, "dd/MM/yy", provider) 
                || txtComEndDate.Text != (String.Empty) && DateTime.Parse(itemDate) <= DateTime.ParseExact(txtComEndDate.Text, "dd/MM/yy", provider)
                || (txtComStartDate.Text != (String.Empty) && DateTime.Parse(itemDate) >= DateTime.ParseExact(txtComStartDate.Text, "dd/MM/yy", provider) && txtComEndDate.Text != (String.Empty) && DateTime.Parse(itemDate) <= DateTime.ParseExact(txtComEndDate.Text, "dd/MM/yy", provider)))
            {
                string itemAuthor = itemElement.GetElementsByTagName("author")[0].InnerText;
                string itemTitle = itemElement.GetElementsByTagName("title")[0].InnerText;
                string itemDescription = itemElement.GetElementsByTagName("description")[0].InnerText;
                string itemXMLFile = Path.GetFileNameWithoutExtension(fileName);

                richComByTemplate.AppendText("SYMBOL: " + itemXMLFile + "\nAUTHOR: " + itemAuthor + "\nDATE: " + itemDate + 
                                            "\nTITLE: " + itemTitle + "\nDESCRIPTION: " + itemDescription + "\n\n--------\n\n");
            }
        }
    }
}
  • 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-10T00:22:49+00:00Added an answer on June 10, 2026 at 12:22 am

    Your short circuiting is failing, because it gets to the DateTime.Parse(txtComStartDate.Text) and fails. You should allow it to short circuit when any of those fail to ignore the results:

    DateTime startDate, endDate;
    if ((!DateTime.TryParseExact(txtComStartDate.Text, "dd/MM/yy", provider, DateTimeStyles.AssumeLocal, out startDate) 
            || DateTime.Parse(itemDate, provider, DateTimeStyles.AssumeLocal) >= startDate) && 
        (!DateTime.TryParseExact(txtComEndDate.Text, "dd/MM/yy", provider, DateTimeStyles.AssumeLocal, out endDate)
            || DateTime.Parse(itemDate, provider, DateTimeStyles.AssumeLocal) <= endDate))
    {
        // Do something here.
    }
    

    The way you’re going to read this is “Either I can’t parse the start date (meaning the user omitted it or it’s not valid) or the item date is greater than the start date; AND either the end date can’t be parsed (again, either omitted or invalid) or the item date is less than the end date.”

    Take advantage of the short circuit here. If you can’t parse the start date or end date, then it won’t bother checking the item date for that boundary. However, because of the &&, it will check both (unless the item date is before the specified start date, in which case it can skip the record).

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

Sidebar

Related Questions

Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
I'm trying make a login window where a user is prompted to enter their
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to make an xna game, where the user needs to tap to stop
I'm trying to make a simple Scheme interpreter in Haskell. As part of this,
I'm trying to build a python solution where a user can enter a credit
I have a DOM situation that looks like this: A is an ancestor of
I'm gonna split this question into 'Situation' , 'Task' , 'Confusion' & 'Question' to
i'm trying to make some sort of Business Simulation Game and everything is working
I'm trying make an entity with doctrine that has three associations with other entities

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.