Date Form Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two date fields within a form which are then posted to another asp. I
would like when posted, for the receiving form to calculate the difference in
days between the two days, and to be shown in a new field "days difference".
Thanks
 
On the second page put:

<%
dim dtFirstDate, dtSecondDate, dtDaysDifferent

dtFirstDate = request.form("FirstDateField")
dtSecondDate = request.form("SecondDateField")

dtDaysDifferent = DateDiff("d",dtFirstDate,dtSecondDate)
%>

Then, in the field where you want the difference in days use the value in
the dtDaysDifferent variable. Ex:

<input type="text" name="DaysDifferent" size="20"
value="<%=dtDaysDifferent%>">

You should also do some checking first to make sure that both values being
passed to the page contain a date otherwise the math will fail.
 
David, spot on first time, thank you so much. Whilt you are on a roll !!! Can
this be extended to include time of day as well please? The input fields
(dtFirstDate) do include a time i.e 26-Jun-2007 12:55:18
Dont worry if this is difficult, Im delighted with your original reply,
cheers Mick
 
See http://www.devguru.com/technologies/vbscript/quickref/datediff.html

--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
_____________________________________________


| David, spot on first time, thank you so much. Whilt you are on a roll !!! Can
| this be extended to include time of day as well please? The input fields
| (dtFirstDate) do include a time i.e 26-Jun-2007 12:55:18
| Dont worry if this is difficult, Im delighted with your original reply,
| cheers Mick
|
| "David Berry" wrote:
|
| > On the second page put:
| >
| > <%
| > dim dtFirstDate, dtSecondDate, dtDaysDifferent
| >
| > dtFirstDate = request.form("FirstDateField")
| > dtSecondDate = request.form("SecondDateField")
| >
| > dtDaysDifferent = DateDiff("d",dtFirstDate,dtSecondDate)
| > %>
| >
| > Then, in the field where you want the difference in days use the value in
| > the dtDaysDifferent variable. Ex:
| >
| > <input type="text" name="DaysDifferent" size="20"
| > value="<%=dtDaysDifferent%>">
| >
| > You should also do some checking first to make sure that both values being
| > passed to the page contain a date otherwise the math will fail.
| >
| > --
| > David Berry
| > Microsoft MVP - FrontPage
| > FrontPage Support: http://www.frontpagemvps.com/
| > -----------------------------------
| > To assist you in getting the best answers for FrontPage support see:
| > http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
| > -----------------------------------
| >
| >
| > | > >I have two date fields within a form which are then posted to another asp.
| > >I
| > > would like when posted, for the receiving form to calculate the difference
| > > in
| > > days between the two days, and to be shown in a new field "days
| > > difference".
| > > Thanks
| >
 
Back
Top