compare dates

Discussion in 'ASP .Net' started by =?Utf-8?B?TWFubnkgQ2hvaGFu?=, Sep 25, 2005.

  1. i have two date fields for event start date and end date. I let the user
    enter two on create event page. on submit, i need to compare if the end date
    is earlier than start date or not.

    How can i compare two dates?

    Thanks

    Manny
     
    =?Utf-8?B?TWFubnkgQ2hvaGFu?=, Sep 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?TWFubnkgQ2hvaGFu?=

    Derek Harmon Guest

    "Manny Chohan" <> wrote in message news:...
    > enter two on create event page. on submit, i need to compare if the end date
    > is earlier than start date or not.
    >
    > How can i compare two dates?


    Assuming these are TextBoxes, parse the Text in the TextBox into a
    DateTime,

    DateTime startDate = DateTime.Parse( startDateTextBox.Text);
    // . . .

    then compare the two DateTimes in an if statement,

    if( endDate < startDate )
    {
    warningLabel.Text = "End date/time must be on or after Start date/time.";
    }

    If the text is not formatted correctly as a DateTime, then Parse( ) will
    throw a FormatException (so as a practical matter, you should put that
    code into a try...catch block).

    You may also want to consider the effect of a user entering a date and/or
    time in the format customary for other cultures (for instance, swapping
    the sequence in which day and month are expected).

    Derek Harmon
     
    Derek Harmon, Sep 26, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    910
    Rob Schieber
    Sep 30, 2005
  2. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    235
    Mark Schupp
    Aug 9, 2004
  3. Replies:
    1
    Views:
    240
    Jano Svitok
    Jul 17, 2007
  4. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    265
    Eric I.
    Jun 8, 2008
  5. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    191
    Dr J R Stockton
    Jun 18, 2007
Loading...

Share This Page