Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageyou 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 selec
t
> 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
>
>
>
Post Follow-up to this message'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" <simon.cornforth@blueyonder.co.uk> wrote in message news:hB8fd.153996$BI5.127858@fe2.news.blueyonder.co.uk... > 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 > >
Post Follow-up to this messageDon't you need to put "#"'s around the literals of a date ?
"Simon" <simon.cornforth@blueyonder.co.uk> wrote in message
news:hB8fd.153996$BI5.127858@fe2.news.blueyonder.co.uk...
> 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
Post Follow-up to this messageThanks 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" <mschupp@ielearning.com> wrote in message news:e7xZsTruEHA.2192@TK2MSFTNGP14.phx.gbl... > '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" <simon.cornforth@blueyonder.co.uk> wrote in message > news:hB8fd.153996$BI5.127858@fe2.news.blueyonder.co.uk... > select is > >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.