Days between dates

A

AL

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
A

AL

Just adding to this post....I have tried using some of the code listed on
here by S.Y.M. Wong A Ton and Sandeep and keep getting the following in the
field when it checks the formula:

Expected value type: end-of-string

Actual value: name
Dim -->strStartDate<--

Thanks,
Al...
 
S

S.Y.M. Wong-A-Ton

A

AL

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison
 
S

S.Y.M. Wong-A-Ton

You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
 
A

AL

Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

S.Y.M. Wong-A-Ton said:
You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


AL said:
Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison
 
S

S.Y.M. Wong-A-Ton

Since more folks have been having problems with the solution posted on my
website, I will modify it over the weekend to include a form and controls to
show step-by-step how this is done. Check the site out again on Monday.
---
S.Y.M. Wong-A-Ton


AL said:
Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

S.Y.M. Wong-A-Ton said:
You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


AL said:
Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
S

S.Y.M. Wong-A-Ton

I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


AL said:
Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

S.Y.M. Wong-A-Ton said:
You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


AL said:
Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
P

Paulo Pina

Hi,

I have implemented the VBScript
(http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.

Someone can help?

Thanks in advance,

Paulo Pina



S.Y.M. Wong-A-Ton said:
I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


AL said:
Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

S.Y.M. Wong-A-Ton said:
You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


:

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
S

S.Y.M. Wong-A-Ton

Since you've bound your form to a database, I'm guessing that you're using
the calculation within a repeating section or table? The example on my
website uses just two date pickers that are not repeating. If you want to
extend the sample to a repeating table, you'll have to retrieve the date
pickers and total fields for each row in a repeating group and perform the
calculation for each row.
---
S.Y.M. Wong-A-Ton


Paulo Pina said:
Hi,

I have implemented the VBScript
(http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.

Someone can help?

Thanks in advance,

Paulo Pina



S.Y.M. Wong-A-Ton said:
I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


AL said:
Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

:

You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


:

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
A

AL

Hi,

Thank you so much for making the changes!!!

I have modified the code accordingly and added the extra field and all works
great. The user will be extremely happy :)

Thank you again and GREAT code....

Cheers,
AL

S.Y.M. Wong-A-Ton said:
Since you've bound your form to a database, I'm guessing that you're using
the calculation within a repeating section or table? The example on my
website uses just two date pickers that are not repeating. If you want to
extend the sample to a repeating table, you'll have to retrieve the date
pickers and total fields for each row in a repeating group and perform the
calculation for each row.
---
S.Y.M. Wong-A-Ton


Paulo Pina said:
Hi,

I have implemented the VBScript
(http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.

Someone can help?

Thanks in advance,

Paulo Pina



S.Y.M. Wong-A-Ton said:
I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


:

Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

:

You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


:

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
S

S.Y.M. Wong-A-Ton

Glad I could help.
---
S.Y.M. Wong-A-Ton


AL said:
Hi,

Thank you so much for making the changes!!!

I have modified the code accordingly and added the extra field and all works
great. The user will be extremely happy :)

Thank you again and GREAT code....

Cheers,
AL

S.Y.M. Wong-A-Ton said:
Since you've bound your form to a database, I'm guessing that you're using
the calculation within a repeating section or table? The example on my
website uses just two date pickers that are not repeating. If you want to
extend the sample to a repeating table, you'll have to retrieve the date
pickers and total fields for each row in a repeating group and perform the
calculation for each row.
---
S.Y.M. Wong-A-Ton


Paulo Pina said:
Hi,

I have implemented the VBScript
(http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.

Someone can help?

Thanks in advance,

Paulo Pina



:

I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


:

Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

:

You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


:

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
S

Scott

Hoping you can help. I followed your example and successfully added to my
form. My form contains a Repeating Section titled 'Action Items' which I am
using to track Call Center issues, so during any day we might have a dozen
'Action Items' all of which contain different information.

I want to use the Date Difference to track calls that are taking longer than
5 days, but your example only works on the first 'Action Item'. Once a user
of the form repeats the section the functionality of your Date Difference no
longer works.

Is there a way to have the date difference piece work for a repeating section?

Thank you in advance for any help.
Scott
Glad I could help.
---
S.Y.M. Wong-A-Ton


AL said:
Hi,

Thank you so much for making the changes!!!

I have modified the code accordingly and added the extra field and all works
great. The user will be extremely happy :)

Thank you again and GREAT code....

Cheers,
AL

S.Y.M. Wong-A-Ton said:
Since you've bound your form to a database, I'm guessing that you're using
the calculation within a repeating section or table? The example on my
website uses just two date pickers that are not repeating. If you want to
extend the sample to a repeating table, you'll have to retrieve the date
pickers and total fields for each row in a repeating group and perform the
calculation for each row.
---
S.Y.M. Wong-A-Ton


:

Hi,

I have implemented the VBScript
(http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.

Someone can help?

Thanks in advance,

Paulo Pina



:

I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton


:

Thank you for responding again.

The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.

I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.

I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this :(

Thanks and regards,
Al

:

You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.

I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.

To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor

You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton


:

Thanks S.Y.M. Wong-A-Ton.

I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?

Thanks and best regards,
Alison

:

Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates. :)

Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm

Hope this helps.
---
S.Y.M. Wong-A-Ton


:

Hi,

I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?

If anyone can shed some light on this for me, I'd be more than grateful.

Al...
 
B

Ben Walters

Hey Al,
There is no function in the Declarative logic engine to do this, I have
achieved this historically by using code.
I know you mentioned that your not a "coding wizard " so I've included the
code required below (2 sets one for calculating working days and one for
calculating the number of days passed), also if you follow the this link
you'll find a video showing you how to add this
code to your form

<------START Calculate working days --->
//Code for calculating working days e.g. number of days between 2 dates
excluding Sat and Sun

int CalculatedDays = 1; //Create int to track the number of days
XPathNavigator Main = this.CreateNavigator(); //Create Xpath
navigator to access the Main data source

//Get the start date entered in the form
DateTime StartDate =
DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:DateStart",
this.NamespaceManager).Value.ToString());
//Get the end date entered in the form
DateTime EndDate =
DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:DateEnd",
this.NamespaceManager).Value.ToString());
//Create the Time span object to calculated the time passed
between the 2 dates
TimeSpan ts = EndDate.Subtract(StartDate);

//Loop throug the days entered and add each day thats not a
sunday or saturday
for (int i = 1; i <= ts.Days; i++)
{
StartDate = StartDate.AddDays(1);
if (StartDate.DayOfWeek != DayOfWeek.Sunday &&
StartDate.DayOfWeek != DayOfWeek.Saturday)
{
CalculatedDays++;
}

}
//Update the field in the form with the total calculated days
Main.SelectSingleNode("/my:myFields/my:WorkingDays",
this.NamespaceManager).SetValue(CalculatedDays.ToString());

<------END Calculate working days --->

<------START Calculate days Difference --->
XPathNavigator Main = this.CreateNavigator(); //Create Xpath navigator to
access the Main data source

//Get the start date entered in the form
DateTime StartDate =
DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:DateStart",
this.NamespaceManager).Value.ToString());
//Get the end date entered in the form
DateTime EndDate =
DateTime.Parse(Main.SelectSingleNode("/my:myFields/my:DateEnd",
this.NamespaceManager).Value.ToString());
//Create the Time span object to calculated the time passed
between the 2 dates
TimeSpan ts = EndDate.Subtract(StartDate);

//Update the field in the form with the total calculated days
Main.SelectSingleNode("/my:myFields/my:DaysDiffference",
this.NamespaceManager).SetValue(ts.Days);


<------ENDCalculate days Difference--->


Hope this helps

Cheers
Ben walters
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top