Date vaidation after form submission

Discussion in 'ASP General' started by Simon, Oct 25, 2004.

  1. Simon

    Simon Guest

    Hi there.

    I have a form on which I have a date of expiry which is built from 3 select
    fields to build the day, month and year, this all works OK and the data is
    being built and added to the database no problem.

    However, I want to validate this date to ensure it is in the future, the
    following validation does not work, any ideas?

    'get data from form
    ExpiresDD = Request.Form("ExpiresDDin")
    ExpiresMM = Request.Form("ExpiresMMin")
    ExpiresYY = Request.Form("ExpiresYYin")

    'build the date
    Expires = ExpiresDD & "/" & ExpiresMM & "/" & ExpiresYY

    'validate for in the future
    if Expires <= Date then
    errorSameDate = "True"
    errorTrap = "True"
    end if

    I have also tried isDate(Expires) to check if todays date, as in, but no
    luck again, obvs submitting todays date!

    if isDate(Expires) then
    errorSameDate = "True"
    errorTrap = "True"
    end if

    Hope someone can help.

    Cheers

    Simon
     
    Simon, Oct 25, 2004
    #1
    1. Advertising

  2. Simon

    thorpe Guest

    you need to look into the 'dateadd' function.

    "Simon" wrote:

    > Hi there.
    >
    > I have a form on which I have a date of expiry which is built from 3 select
    > fields to build the day, month and year, this all works OK and the data is
    > being built and added to the database no problem.
    >
    > However, I want to validate this date to ensure it is in the future, the
    > following validation does not work, any ideas?
    >
    > 'get data from form
    > ExpiresDD = Request.Form("ExpiresDDin")
    > ExpiresMM = Request.Form("ExpiresMMin")
    > ExpiresYY = Request.Form("ExpiresYYin")
    >
    > 'build the date
    > Expires = ExpiresDD & "/" & ExpiresMM & "/" & ExpiresYY
    >
    > 'validate for in the future
    > if Expires <= Date then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > I have also tried isDate(Expires) to check if todays date, as in, but no
    > luck again, obvs submitting todays date!
    >
    > if isDate(Expires) then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > Hope someone can help.
    >
    > Cheers
    >
    > Simon
    >
    >
    >
     
    thorpe, Oct 25, 2004
    #2
    1. Advertising

  3. Simon

    Mark Schupp Guest

    'validate for in the future
    if CDate(Expires) <= Date then
    errorSameDate = "True"
    errorTrap = "True"
    end if

    You might want to use a non-ambiguous date format as well before you get
    bitten by the UK vs US date format differences

    Expires = "20" & ExpiresYY & "-" & ExpiresMM & "-" & ExpiresDD
    If not IsDate(Expires) Then
    'put bad date error code here
    End If

    --
    Mark Schupp
    Head of Development
    Integrity eLearning
    www.ielearning.com


    "Simon" <> wrote in message
    news:hB8fd.153996$...
    > Hi there.
    >
    > I have a form on which I have a date of expiry which is built from 3

    select
    > fields to build the day, month and year, this all works OK and the data is
    > being built and added to the database no problem.
    >
    > However, I want to validate this date to ensure it is in the future, the
    > following validation does not work, any ideas?
    >
    > 'get data from form
    > ExpiresDD = Request.Form("ExpiresDDin")
    > ExpiresMM = Request.Form("ExpiresMMin")
    > ExpiresYY = Request.Form("ExpiresYYin")
    >
    > 'build the date
    > Expires = ExpiresDD & "/" & ExpiresMM & "/" & ExpiresYY
    >
    > 'validate for in the future
    > if Expires <= Date then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > I have also tried isDate(Expires) to check if todays date, as in, but no
    > luck again, obvs submitting todays date!
    >
    > if isDate(Expires) then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > Hope someone can help.
    >
    > Cheers
    >
    > Simon
    >
    >
     
    Mark Schupp, Oct 25, 2004
    #3
  4. Simon

    Hal Rosser Guest

    Don't you need to put "#"'s around the literals of a date ?

    "Simon" <> wrote in message
    news:hB8fd.153996$...
    > Hi there.
    >
    > I have a form on which I have a date of expiry which is built from 3

    select
    > fields to build the day, month and year, this all works OK and the data is
    > being built and added to the database no problem.
    >
    > However, I want to validate this date to ensure it is in the future, the
    > following validation does not work, any ideas?
    >
    > 'get data from form
    > ExpiresDD = Request.Form("ExpiresDDin")
    > ExpiresMM = Request.Form("ExpiresMMin")
    > ExpiresYY = Request.Form("ExpiresYYin")
    >
    > 'build the date
    > Expires = ExpiresDD & "/" & ExpiresMM & "/" & ExpiresYY
    >
    > 'validate for in the future
    > if Expires <= Date then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > I have also tried isDate(Expires) to check if todays date, as in, but no
    > luck again, obvs submitting todays date!
    >
    > if isDate(Expires) then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > Hope someone can help.
    >
    > Cheers
    >
    > Simon
    >
    >



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.781 / Virus Database: 527 - Release Date: 10/22/2004
     
    Hal Rosser, Oct 26, 2004
    #4
  5. Simon

    Simon Guest

    Thanks for that, again I managed a work around, but that was cleaner and
    less code.

    Luckily, in this case as well, the server and the users are in the UK, so no
    US date issues.

    Cheers

    Simon

    "Mark Schupp" <> wrote in message
    news:...
    > 'validate for in the future
    > if CDate(Expires) <= Date then
    > errorSameDate = "True"
    > errorTrap = "True"
    > end if
    >
    > You might want to use a non-ambiguous date format as well before you get
    > bitten by the UK vs US date format differences
    >
    > Expires = "20" & ExpiresYY & "-" & ExpiresMM & "-" & ExpiresDD
    > If not IsDate(Expires) Then
    > 'put bad date error code here
    > End If
    >
    > --
    > Mark Schupp
    > Head of Development
    > Integrity eLearning
    > www.ielearning.com
    >
    >
    > "Simon" <> wrote in message
    > news:hB8fd.153996$...
    > > Hi there.
    > >
    > > I have a form on which I have a date of expiry which is built from 3

    > select
    > > fields to build the day, month and year, this all works OK and the data

    is
    > > being built and added to the database no problem.
    > >
    > > However, I want to validate this date to ensure it is in the future, the
    > > following validation does not work, any ideas?
    > >
    > > 'get data from form
    > > ExpiresDD = Request.Form("ExpiresDDin")
    > > ExpiresMM = Request.Form("ExpiresMMin")
    > > ExpiresYY = Request.Form("ExpiresYYin")
    > >
    > > 'build the date
    > > Expires = ExpiresDD & "/" & ExpiresMM & "/" & ExpiresYY
    > >
    > > 'validate for in the future
    > > if Expires <= Date then
    > > errorSameDate = "True"
    > > errorTrap = "True"
    > > end if
    > >
    > > I have also tried isDate(Expires) to check if todays date, as in, but no
    > > luck again, obvs submitting todays date!
    > >
    > > if isDate(Expires) then
    > > errorSameDate = "True"
    > > errorTrap = "True"
    > > end if
    > >
    > > Hope someone can help.
    > >
    > > Cheers
    > >
    > > Simon
    > >
    > >

    >
    >
     
    Simon, Oct 26, 2004
    #5
    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. Matt
    Replies:
    1
    Views:
    646
    Matthew Speed
    Nov 8, 2003
  2. Random

    vaidation and non-server controls

    Random, Feb 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    728
    Random
    Feb 4, 2005
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,367
    Michael Borgwardt
    May 30, 2004
  4. Laery
    Replies:
    11
    Views:
    1,002
    Laery
    Feb 25, 2005
  5. Jared
    Replies:
    5
    Views:
    234
    Jared
    Jul 10, 2003
Loading...

Share This Page