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:
Last day of the month
-
- PhraseExpress Expert
- Posts: 913
- Joined: 27 Feb 08, 15:07
@mh348
Try this and adapt it for your applications:
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
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}}}
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
Peter,
seriously, this makes my head spin. What on earth are you doing here? Care to explain step by step. Fascinating indeed.
seriously, this makes my head spin. What on earth are you doing here? Care to explain step by step. Fascinating indeed.
-
- PhraseExpress Expert
- Posts: 913
- Joined: 27 Feb 08, 15:07
@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
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
Simply brilliant !
Thank you.
Thank you.