Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Get yesterdays date with UDF @PREVDATE

Aug
2,799
144
Using the @DATEPLUS function from the ISO8601 plugin,
here is a UDF @PREVDATE function;

Code:
R:\>function prevdate=`%@dateplus[%1,-1]`

R:\>echo %_isodate   %@prevdate[%_isodate]
2026-07-23   2026-07-22

Joe
 
If you know that all the dates involved will be 1980 or later, you can also use internal functions:

Code:
C:\>function prevdate=`%@makedate[%@dec[%@date[%$]]]`

C:\>echo %@prevdate[11/04/2008]
11/03/08

C:\>echo %@prevdate[03/01/1988]
02/29/88

C:\>echo %@prevdate[]
07/22/26

C:\>

TCC's date functions use the MS-DOS epoch of 1980-01-01, so dates before that will fail.
 
I like working with FILETIMEs. This'll go back farther but it'll be fussy about the date format.

Code:
v:\> function prevdate `%@word[",",0,%@agedate[%@eval[%@makeage[%@if[%# GT 0,%1,%_date]] - 864000000000]]]`

v:\> echo %@prevdate[]
2026-07-22

v:\> echo %@prevdate[2000-03-01]
2000-02-29

v:\> echo %@prevdate[1900-03-01]
1900-02-28
 
On my PC, I have renamed the GNU/Linux date utility to "unixdate.exe", and it has a very rich feature set for specifying dates in the past. For example:

[ 1:48] > unixdate -d yesterday
Wed, Jul 22, 2026 1:48:29 PM

[ 1:48] > unixdate -d "last month"
Tue, Jun 23, 2026 1:49:31 PM

[ 1:49] > unixdate -d "3 weeks ago"
Thu, Jul 2, 2026 1:52:39 PM

There are some really useful, easy-to-use utilities in the command-line world.
 
Speaking of date/time formats ... I've been working on an old Windows time synchronization service and was reminded of the NTP (Network Time Protocol) format. It is a 64-bit big-endian (network-order) fixed-point representation of the number of seconds since 1900-01-01 00:00:00 UTC. The high 32 bits contain the whole seconds, and the low 32 bits contain the numerator (with an implied denominator of 2³²) of the fractional part of a second. That's even finer than a FILETIME.
 
Back
Top