HP3000-L Archives

November 2004, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Larry Barnes <[log in to unmask]>
Reply To:
Larry Barnes <[log in to unmask]>
Date:
Thu, 4 Nov 2004 09:41:48 -0800
Content-Type:
text/plain
Parts/Attachments:
text/plain (101 lines)
Here's a bit different use of DATEADD

setvar eom dateadd(today,0,1,-!hpday)+1 

-----Original Message-----
From: Emerson, Tom [mailto:[log in to unmask]] 
Sent: Thursday, November 04, 2004 9:35 AM
To: [log in to unmask]
Subject: Re: [HP3000-L] MPEX Feature of the Day - Last Day of The Month

[ok, so I'm not quite gone -- sue me :) -- however I've just sub'd to
the openmpe list, so after this I REALLY will unsub this list (and many
thanks to those that responded privately)]

> -----Original Message-----
> From: HP-3000 Systems Discussion [mailto:[log in to unmask]]On
> Subject: [HP3000-L] MPEX Feature of the Day - Last Day of The Month
> 
> This is one of those things discovered when trying to find a solution 
> to an old problem.
> 
> Putting the Last Day of Last Month automatically into a job stream 
> parameter. [...] I spent a hour or so perusing VESoft Expressions 
> section of the MPEX manual.

I thought I had an example in there for this one specifically
[checking...]

[...nope, not finding it right off... darn :) ]

but:

> Finally I take a look at the DATEADD function, and get the proverbial 
> "light-bulb" of Eureka, and get what I need with two SETVARs just 
> prior to the JOB card:
> 
> ::SETVAR EOM DATEADD(TODAY,0,0,-!HPDATE) ::SETVAR EOMSTR 
> CDATE(!EOM,"MMDDYY")
[...]
> Although it may go wrong if the you're already on the last day, and 
> the next month has less days than the current month.

well...

The first of the current month is always:

   DATEBUILD(HPYEAR,HPMONTH,1)

Since DATEADD can work with "months" as well as days, the first of the
next month would be:

   DATEADD(<prevcalc>,0,1,0)

and likewise, the LAST day of the previous month is one day prior to the
first of the month, so you have:

   DATEADD(<prevcalc>,0,0,-1)

which can all be strung together:

   DATEADD(DATEADD(DATEBUILD(HPYEAR,HPMONTH,1),0,1,0),0,0,-1)

and proving it online:
%CALC DATEADD(DATEADD(DATEBUILD(HPYEAR,HPMONTH,1),0,1,0),0,0,-1)
04/11/30


BUT WAIT, there's more...

you can combine the DATEADDs by specifying BOTH "+1 month" and "-1 day"
as paramters:

%calc dateadd(datebuild(hpyear,hpmonth,1),0,1,-1)
04/11/30

and does it work for EVERY month? well, take a look:

%repeat
%>calc dateadd(datebuild(hpyear,m,1),0,1,-1)
%>fornum m=1,12
04/01/31
04/02/29
04/03/31
04/04/30
04/05/31
04/06/30
04/07/31
04/08/31
04/09/30
04/10/31
04/11/30
04/12/31

it even got the LEAP DAY correct!

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2