Adding days to user input date?

User-to-User discussion about the PhraseExpress macro programming.
Forum rules
Please read the forum disclaimer. Thank you!
Post Reply
semhof
Posts: 13
Joined: 08 Sep 16, 21:56

Adding days to user input date?

Post by semhof » 14 Apr 17, 22:21

Is it possible to generate a date in relation to a user-input date?

I would like to prompt the user for a given date )via a date picker), insert that into the phrase, and later in the same phrase automatically insert a date 60 days after the first date chosen by the user.

Can PhraseExpress do this?

Thanks!

Peter Stotz
PhraseExpress Expert
Posts: 564
Joined: 27 Feb 08, 15:07

Re: Adding days to user input date?

Post by Peter Stotz » 15 Apr 17, 09:34

Oh yes, handling of dates is one of the strength of PhraseExpress:

Code: Select all

{#settemp -name ##date_via_calendar -content {#calendar -f dd.mm.yyyy -head Pick a date: -manual}}Date via calendar-Makro chosen by the user    : {#gettemp ##date_via_calendar}
Date 60 days after the date via Calendar-Makro: {#datetime -f dd.mm.yyyy -value {#gettemp ##date_via_calendar} -s 60D}
The -value-parameter does the trick...

Output
Date via calendar-Makro chosen by the user__: 01.01.2017
Date 60 days after the date via Calendar-Makro: 02.03.2017

Manual:
#datetime see here: http://www.phraseexpress.com/docs12/09/ ... Formatting
#calendar see here: http://www.phraseexpress.com/docs12/09/ ... m#Calendar

Peter
Win 10-1607 64 bit - PhraseExpress 12.0.143i

semhof
Posts: 13
Joined: 08 Sep 16, 21:56

Re: Adding days to user input date?

Post by semhof » 19 Apr 17, 18:31

Thanks, Peter. Unfortunately, I am having trouble getting PhraseExpress to recognize the -value parameter. When I run the phrase you provided, I get this output:

Date via calendar-Makro chosen by the user : 01.01.2017
Date 60 days after the date via Calendar-Makro: 18.06.2017

The date shift is always performed based on today's date, not the user input date.

Peter Stotz
PhraseExpress Expert
Posts: 564
Joined: 27 Feb 08, 15:07

Re: Adding days to user input date?

Post by Peter Stotz » 19 Apr 17, 19:22

Strange!
Apparently the parameter -value <date> doesn't work correct...
What happens if you use an other date format?
{#datetime -f dd.mm.yyyy -value {#gettemp ##date_via_calendar} -s 60D} is the correct code...

Sometimes necessary blanks are not indicated by the forum software...
e.g. -value19.04.2017 does not work

And: Do you use the latest version of PhraseExpress?

Peter
Win 10-1607 64 bit - PhraseExpress 12.0.143i

semhof
Posts: 13
Joined: 08 Sep 16, 21:56

Re: Adding days to user input date?

Post by semhof » 19 Apr 17, 21:33

Yes, I am running v12.0.143p, which I believe is the latest version.

The date format does not seem to make a difference. When I change the format to <mmmm d, yyyy> which is what I ultimately want, it still shifts the second date based on today's date, rather than the user input date.

So, the phrase:

Code: Select all

{#settemp -name ##date_via_calendar -content {#calendar -f mmmm d, yyyy -head Pick a date: -manual}}Date via calendar-Makro chosen by the user    : {#gettemp ##date_via_calendar}
Date 60 days after the date via Calendar-Makro: {#date -f mmmm d, yyyy -value {#gettemp ##date_via_calendar} -s 60D}
Outputs to:
Date via calendar-Makro chosen by the user : January 1, 2017
Date 60 days after the date via Calendar-Makro: June 18, 2017

Peter Stotz
PhraseExpress Expert
Posts: 564
Joined: 27 Feb 08, 15:07

Re: Adding days to user input date?

Post by Peter Stotz » 20 Apr 17, 10:26

Hmm - there is a typo: {#date -f mmmm d, yyyy -value ... - should be: {#datetime -f mmmm d, yyyy -value ...
But the point is:
there seems to be a problem with reformatting and -s xD if the -value-parameter is in a long date format dddddd / mmmm d, yyyy / ...
Would the developers please have a look at it?

This fails:
{#settemp -name ##date_via_calendar -content {#calendar -f mmmm d, yyyy -head Pick a date: -manual}}Date via calendar-Makro chosen by the user : {#gettemp ##date_via_calendar}
Date 60 days after the date via Calendar-Makro: {#datetime -f mmmm d, yyyy -value {#gettemp ##date_via_calendar} -s 60D}
This fails: {#datetime -f ddddd -value {#gettemp ##date_via_calendar}} (should be a reformatted {#gettemp ##date_via_calendar} ...)
Output:
Date via calendar-Makro chosen by the user : Januar 1, 2017
Date 60 days after the date via Calendar-Makro: Juni 19, 2017
This fails: 20.04.2017 (should be a reformatted Januar 1, 2017 ...)

This works:
{#settemp -name ##date_via_calendar -content {#calendar -f ddddd -head Pick a date: -manual}}Date via calendar-Makro chosen by the user : {#datetime -f mmmm d, yyyy -value {#gettemp ##date_via_calendar}}
Date 60 days after the date via Calendar-Makro: {#datetime -f mmmm d, yyyy -value {#gettemp ##date_via_calendar} -s 60D}
Output:
Date via calendar-Makro chosen by the user : Januar 1, 2017
Date 60 days after the date via Calendar-Makro: März 2, 2017

Peter
Win 10-1607 64 bit - PhraseExpress 12.0.143i

Klein
PhraseExpress Expert
Posts: 129
Joined: 24 Mar 14, 16:11

Re: Adding days to user input date?

Post by Klein » 20 Apr 17, 11:44

It seems, the default for a date by means of variables must occur in a certain format.

I have written this already in this answer. viewtopic.php?p=49338#p49338

semhof
Posts: 13
Joined: 08 Sep 16, 21:56

Re: Adding days to user input date?

Post by semhof » 20 Apr 17, 19:18

Thanks! Specifying the date format to <ddddd> when setting the variable works!

I have a follow-up question: When I run this phrase, or seemingly any phrase which sets a variable, the first thing that happens is that I am asked to set the variable, even if that macro is not at the beginning of the phrase.

For example, when I run this phrase:

Code: Select all

	The opening brief and excerpts of record are due {#settemp -name ##OpeningBrief -content {#calendar -f ddddd -head Opening Brief Due Date -manual}}{#datetime -f mmmm d, yyyy -value {#gettemp ##OpeningBrief}}; the answering brief is due {#datetime -f mmmm d, yyyy -value{#gettemp ##OpeningBrief} -s 60d}; and the optional reply brief is due within 14 days after service of the answering brief.
I am first asked to set the date, instead of first seeing the text "The opening brief and excerpts of record are due"

I do not see this behavior if I simply run a phrase with a date picker. The phrase:

Code: Select all

Enter a date: {#calendar -f mmmm d, yyyy -manual}
first displays the text "Enter a date: " and then a date-picker appears.

Is this a bug, or is there a setting or parameter I can modify so that the user-input set-variable box appears when it occurs in the actual text of the phrase?

Thank you very much for all of your help!

Peter Stotz
PhraseExpress Expert
Posts: 564
Joined: 27 Feb 08, 15:07

Re: Adding days to user input date?

Post by Peter Stotz » 20 Apr 17, 20:27

PhraseExpress macros are hierarchically executed - #form macros for example have a very high priority.
The #settemp macro in your phrase has a higher priority as the text output.

For a shorter form of your phrase you can re-use the selected #calendar-date in various places within your phrase using the identical window title for all instances of the calendar macro.
Then you will see first the text and the #settemp macro with the temporary variable and the #datetime macro are unnecessary:

Code: Select all

The opening brief and excerpts of record are due {#calendar -f mmmm d, yyyy -head Opening Brief Due Date -manual}; the answering brief is due {#datetime -f mmmm d, yyyy -value {#calendar -f ddddd -head Opening Brief Due Date -manual} -s 60d}; and the optional reply brief is due within 14 days after service of the answering brief.
And by the way: there must be a blank character between the value-parameter and the following date:
-value{#gettemp ##OpeningBrief}
-value {#gettemp ##OpeningBrief}

Peter
Win 10-1607 64 bit - PhraseExpress 12.0.143i

semhof
Posts: 13
Joined: 08 Sep 16, 21:56

Re: Adding days to user input date?

Post by semhof » 20 Apr 17, 20:50

Thank you!!

Post Reply