Last day of the month

User-to-User discussion about the PhraseExpress macro programming.
Post Reply
mh348
Posts: 13
Joined: 29 Aug 18, 10:30

Last day of the month

Post by mh348 » 04 Dec 19, 08:54

Hi, how do I add the last day of the month to a phrase?

I need to add the date to a phrase, example, where the last day is either 28,29/30/31:
Account Date: 2019/11/30
Amount Due:

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

Post by Peter Stotz » 04 Dec 19, 23:48

@mh348
Try this and adapt it for your applications:

Code: Select all

(* 20191208 • last day of the month
   reference date (note: use the system standard date format ddddd)
*){#settemp -name ##ddddd -content {#calendar -f ddddd -head reference date? -manual}}(*
  last day of the month
*){#settemp -name ##last_day_of_the_month -content {#datetime -f ddddd -s -1D -value {#datetime -f 01.mm.yyyy -s 1M -value {#gettemp ##ddddd}}}}(*
  Notification and optional output
*){#balloon -title Last day of the month {#datetime -f mmmm yyyy -value {#gettemp ##ddddd} -locale en-GB}:{#asc 13}{#datetime -f ddd, dd.mm.yyyy -value {#gettemp ##last_day_of_the_month} -locale en-GB} -text ... click to output the date -onclick {#datetime -f yyyy'/'mm'/'dd -value {#gettemp ##last_day_of_the_month}}}
Update 08.12.2019:
Old code:
{#substr 31{#datetime -f dd -value 01.03.{#datetime -f yyyy -value {#gettemp ##ddddd}} -s -1D}31303130313130313031 -from {#calc 2*{#datetime -f mm -value {#gettemp ##ddddd}}-1 -round 0} -count 2}.{#datetime -f mm.yyyy -value {#gettemp ##ddddd}}
New code - shorter and more efficient:
{#datetime -f ddddd -s -1D -value {#datetime -f 01.mm.yyyy -s 1M -value {#gettemp ##ddddd}}}

Peter Stotz
Windows 10 - PhraseExpress v14.0.171

mh348
Posts: 13
Joined: 29 Aug 18, 10:30

Post by mh348 » 05 Dec 19, 08:00

Thanks will try this :)

Praia
Posts: 82
Joined: 01 Apr 14, 01:06

Post by Praia » 07 Dec 19, 18:03

Peter,

seriously, this makes my head spin. What on earth are you doing here? Care to explain step by step. Fascinating indeed.

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

Post by Peter Stotz » 07 Dec 19, 23:21

@praia, @all
Last day of the month:
Hmm - the macro was originally from 2008 ...
This algorithm for 'last day of the month' is more efficient:
{#datetime -f dd -s -1D -value 01.{#datetime -f mm.yyyy -s +1M -value {#datetime -f ddddd}}}

I have updated the code in my previous post - thank you Praia for your hint!

The old code
{#substr 31{#datetime -f dd -value 01.03.{#datetime -f yyyy} -s -1d}31303130313130313031 -from {#calc 2*{#datetime -f mm}-1 -round 0} -count 2}.{#datetime -f mm.yyyy}
looks a little bit tricky, but the underlying solution idea is actually quite simple:
• According to the monthly value of the current date, the 2 characters dd of the last day of this monthly value are taken from the string
31xx31303130313130313031
xx = 28 or 29 for February is calculated as shift -s -1D from 01.03.yyyy of the current date (due to leap years).
• {#calc 2*{#datetime -f mm}-1 -round 0} calculates the extraction position of the monthly value in the string.
• Finally, the monthly and annual values of the current date .mm.yyyy are appended to dd for the result output.
Et voilà!

Peter
Windows 10 - PhraseExpress v14.0.171
Translated with www.DeepL.com/Translator

Praia
Posts: 82
Joined: 01 Apr 14, 01:06

Post by Praia » 08 Dec 19, 21:21

Simply brilliant !

Thank you.

Post Reply