locked
C#: DateTime RRS feed

  • Question

  • Hi,

    Hope someone can help me here.

    I have a dateSelected label which produces a date format value (mm-dd-yyyy) and then I need to not allow an entry to be added upon addButton click if the date from label dateSelected is greater than the date today. How can I do it?

    Thanks,

    MukuroRokudo

    Monday, August 5, 2013 3:13 AM

Answers

  • This should help you along the right path:

       string l_labelString = "01-11-2013";
       DateTime l_selectedDate = DateTime.ParseExact(l_labelString, "MM-dd-yyyy", CultureInfo.CurrentCulture);
       if (l_selectedDate <= DateTime.Today)
       {
        // Do stuff
       }


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    Monday, August 5, 2013 3:34 AM
  • Hi,

    Try this.

    if (bucketDropDownListBox.SelectedItem.ToString() == "Holidays"  || bucketDropDownListBox.SelectedItem.ToString() == "Vacation Leaves") 
    {
    
       //do the thing
    
    }

    Refer this: || Operator (C# Reference)


    Microsoft MVP - ASP/ASP.NET

    • Marked as answer by MukuroRokudo Monday, August 5, 2013 5:28 AM
    Monday, August 5, 2013 5:13 AM

All replies

  • This should help you along the right path:

       string l_labelString = "01-11-2013";
       DateTime l_selectedDate = DateTime.ParseExact(l_labelString, "MM-dd-yyyy", CultureInfo.CurrentCulture);
       if (l_selectedDate <= DateTime.Today)
       {
        // Do stuff
       }


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    Monday, August 5, 2013 3:34 AM
  • HI,

    Thanks for the help. I have one more question though. How can I make the statement below to have OR if that's the right term.

    if (bucketDropDownListBox.SelectedItem.ToString() == "Holidays") 

    {

    //do the thing

    }

    I need to have another selection for it. Like "Vacation Leaves"

    So i thought I will make this one but its not working.

    if (bucketDropDownListBox.SelectedItem.ToString() == "Holidays")  || if (bucketDropDownListBox.SelectedItem.ToString() == "Vacation Leaves") 

    {

    //do the thing

    }

    Monday, August 5, 2013 5:05 AM
  • Hi,

    Try this.

    if (bucketDropDownListBox.SelectedItem.ToString() == "Holidays"  || bucketDropDownListBox.SelectedItem.ToString() == "Vacation Leaves") 
    {
    
       //do the thing
    
    }

    Refer this: || Operator (C# Reference)


    Microsoft MVP - ASP/ASP.NET

    • Marked as answer by MukuroRokudo Monday, August 5, 2013 5:28 AM
    Monday, August 5, 2013 5:13 AM