Progress 4GL - Define variable month/year - date

Here's the problem, i need to create a date range on the variable below.
define variable s_date as character format "99/9999" no-undo.
There is a start_date column in my db (format "99/99/9999"(dd/mm/yyyy)) the date when a customer sales order was entered.
What i need to do is set the variable to create the date range, search and display the results of every sales order of the defined month and year.
PS: I 'm using a form , so the user can define the range of the month and year.

Here's something to get you started. You will have to look into converting it to fit your form.
If you're on an older release that haven't got the ADD-INTERVAL function you can use the DATE function and add +1 to the month instead (just remember that if the month is December (12) you're going to have to increase the year instead and set the month to 1).
DEFINE VARIABLE cFromDate AS CHARACTER NO-UNDO.
DEFINE VARIABLE dtFromDate AS DATE NO-UNDO LABEL "From".
DEFINE VARIABLE dtTomDate AS DATE NO-UNDO LABEL "Tom".
DEFINE VARIABLE iMonth AS INTEGER NO-UNDO.
DEFINE VARIABLE iYear AS INTEGER NO-UNDO.
UPDATE cFromDate FORMAT "99/9999" NO-ERROR.
IF LENGTH(cFromDate) <> 6 THEN DO:
MESSAGE "Invalid format" VIEW-AS ALERT-BOX ERROR.
RETURN ERROR.
END.
ASSIGN
iMonth = INTEGER(SUBSTRING(cFromDate,1,2))
iYear = INTEGER(SUBSTRING(cFromDate,3,4)) NO-ERROR.
IF iMonth < 1 OR iMonth > 12 THEN DO:
MESSAGE "Invalid month" VIEW-AS ALERT-BOX ERROR.
RETURN ERROR.
END.
IF iYear < 1990 OR iYear > 2020 THEN DO:
MESSAGE "Invalid year" VIEW-AS ALERT-BOX ERROR.
RETURN ERROR.
END.
ASSIGN
dtFromDate = DATE(iMonth, 1, iYear)
dtTomDate = ADD-INTERVAL(dtFromDate, 1, "month") - 1.
DISPLAY
dtFromDate FORMAT "9999-99-99"
dtTomDate FORMAT "9999-99-99".

Related

How to count events after set date with COUNTIFS?

I'm creating this report in spreadsheet
https://docs.google.com/spreadsheets/d/1U48MybVshKT3eRYE9goRCab9k1KCoXe7Zsr9Ogkkm4Y/edit?usp=sharing
In "BD" you can find the records and in "NB-month" the KPI that I want to analyze; I would like to create DATE filter for the numbers in the columns, ex for the col: "nº Contract closed" I'm thinking to use this formula:
=COUNTIFS(BD!R:R;A5;BD!G:G;">"&DATE(B2))
but I get a value: "0" that is incorrect because for this agent "Carla Vaello" the number of contracts closed after 2020-02-01 should be "2".
your usage of DATE formula is wrong (DATE requires 3 parameters). either change DATE to DATEVALUE or use:
=COUNTIFS(BD!R:R; A5; BD!G:G; ">"&B2)

AppleScript : Time format change + Calendar events

I'm trying to create a script to log my current time and my finish time
do a specific action them sent an email with this same time variable and create a calendar event with this time variable :
set FinsihDate to (current date) + 10 * hours + 30 * minutes
set startingDate to (current date)
set plistR to {FinsihDate:FinsihDate, starteddate:current date}
tell application "System Events"
set plistf to make new property list file ¬
with properties {name:"~/Desktop/MY_Time.plist"}
set plistf's value to plistR
end tell
## Email
property lastWindowID : missing value
tell application "Mail"
set windowIDs to id of windows
if windowIDs does not contain lastWindowID then
set newMessage to make new outgoing message with properties {subject:"Started early", content:"Hi ..., \n \nI started early today : " & (current date) & ", I will leave at " & FinsihDate & "\n \nKind Regards,\nKevin " & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"Name", address:"#apple.com"}
end tell
activate
set lastWindowID to id of window 1
else
tell window id lastWindowID
set visible to false
set visible to true
end tell
activate
end if
end tell
set startDate to date (current date)
set endDate to date FinsihDate
tell application "Calendar"
tell (first calendar whose name is "calendar")
make new event at end of events with properties {summary:"Work", start date:startDate, end date:endDate, description:"ITS Fraud Prevention", location:"Apple"}
end tell
end tell
Time format
the time format on the email is " Monday 4 June 2018 at 14:25:57," when I just want 14:25
I tried this :
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
Result: error "Can’t make \"14:27:02\" into type number." number -1700
from "14:27:02" to number
Calendar
When creating the Calendar event I have this error
error "Can’t get date (date \"Monday 4 June 2018 at 14:29:34\")."
number -1728 from date (date "Monday 4 June 2018 at 14:29:34")
Thanks for itemising the individual errors that you encountered and want fixing. This made is so much easier for me to read this question and decide it was one I wanted to answer, because I don't actually have to test your script at all as I can immediately see what the problems are:
① Your parentheses are in the wrong place. Change this:
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
to this:
set myTime to time string of ((current date) + 10 * hours + 30 * minutes)
② The error indicates that you've tried to take a variable of type date and then declare it again as type date. AppleScript doesn't like this.
Change these two lines:
set startDate to date (current date)
set endDate to date FinsihDate
to this:
set startDate to (current date)
set endDate to FinsihDate
I haven't tested the rest of the script.
P.S. You misspelled your variable name FinsihDate (which I assume is meant to be FinishDate). However, it's misspelled consistently throughout the script, so it doesn't make any practical difference.

Prompt: Date, %Sysfunc(year(&myvar.));

I have a SAS EG 7.1 program that generates reports on a monthly basis. The old process was very manual, where users, amongst other things, were asked to update a macro variable (&date.) with current month-end (Date9.).
%let Date = '28feb2018'd; /* <--- Input the date to be reported */
/* Generate the year and the month based on the input date */
%let year = %sysfunc(year(&date.));
%let month = %sysfunc(month(&date.));
The &year (4-digit) and &month. (1- or 2-digit depending on the month) are later used in the code as components of a filename to pick up current month's tables:
FROM lib.great_table_loc_&year._&month.;
I am trying to make the program dynamic by prompting the user to chose the current month-end date.
The prompt is working, and outputs date9. format.
I then tried using the macro variable &Prompt_date. in the %sysfunc:
%let Date = '&prompt_date.';
%let year = %sysfunc(year(&prompt_date.));
%let month = %sysfunc(month(&prompt_date.));
When I execute, I get the following error messages:
1)
35 %let year = %sysfunc(year(&prompt_date.));
ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or
%QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC
argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
36 %let month = %sysfunc(month(&prompt_date.));
ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or
%QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC
argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
2)
118 lib.great_table_loc_._.
_
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, ;,
(, ',', ANSIMISS, AS, CROSS, EXCEPT, FULL, GROUP, HAVING,
INNER, INTERSECT, JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER,
RIGHT, UNION, WHERE.
ERROR 200-322: The symbol is not recognized and will be ignored.
I've tried creating a separate field for month and year, formatted to YYMMN6., input the &prompt_date. and then put(,n.) to make the value numeric - still nothing.
Has anyone encountered a similar problem?
Any tips on how to get what I want?
Thanks!
You have:
%let Date = '&prompt_date.';
%let year = %sysfunc(year(&prompt_date.));
%let month = %sysfunc(month(&prompt_date.));
Two issues.
you assign &Date but don't use it.
prompt date is DDMONYYYY (date9.). SAS will see that as a string. You need quotes and a d to make it a date.
Try
%let year = %sysfunc(year("&prompt_date."d));
%let month = %sysfunc(month("&prompt_date."d));

Crystal Reports dateadd function error on interval

I have a date field on which my inventory item was bought. Then I have a lifespan field in months eg 240. Now I am trying to calculate the end of the item's lifespan date but I get an error:
numbervar myVariable := ({TABLE.LIFESPAN} * 30);
dateadd("d", myVariable,{#date})
I get the following error: "Date must be between year 1 and 9999"
As soon as I change the variable to: numbervar myVariable := {TABLE.LIFESPAN};
it works without any errors. Also if I change the dateadd formula to dateadd("d", 7200,{#date}) it works.
The format of the field TABLE.LIFESPAN is decimal(9,2) but none of the value has decimals, eg it will be 240.00
I have also tried
numbervar myVariable := Round({TABLE.LIFESPAN} * 30);
I suspect it has something to do with the decimals.
Help will be greatly appreciated.
you will receive this value once your ({TABLE.LIFESPAN} * 40) causes the year to be greater than 9999. So if {#date} were today's date then {TABLE.LIFESPAN} could not be higher than 73955 or so. I would create a formula for ({TABLE.LIFESPAN} *40) and drop it on the canvas and see what that value is on all records and see if you have an unusually high number somewhere.

How to simulate user input in a LibreOffice Base Form via an event driven macro

I have a LibreOffice Base form that allows me to manually add rows to a table. However, the first field of every row is almost always a duplicate of the previous rows first field - Date. Via a macro, I want to automatically fill in the date field so I don't have to manually repeat the information.
Using the PriorToReset event handler, I tried the following:
Sub Main
Dim defaultDate as string
End Sub
Sub PriorToReset(event)
dim Form
dim DateField
Form=event.source
DateField = Form.getByName("Date")
if DateField.Text = "" then
defaultDate = Date
DateField.Text = defaultDate
else
defaultDate = DateField.Text
end if
End Sub
This does put the current date into an empty row, but when I fill out the remaining fields and attempt to save the row, it objects by saying that the Date field is empty. I'm looking at todays date in that field, but the system acts like its empty. If I backspace over just the last digit, replace it and hit enter it accepts it.
Obviously just dumping the date into the "Text" property does not set the indicator that data has been entered. I also experimented with:
DateField.setPropertyValue("Text", defaultDate)
But that errors out completely.
How do I simulate data entry via a macro?
Set the date property of DateField using a variable declared as an UNO Date Struct.
First, declare the struct. Then set the values of the individual members of the struct (year, month, day). Then set the date property to equal the struct and commit.
Adapt this code example to suit:
Sub change_a_date
Dim adate As New com.sun.star.util.Date
root_form = ThisComponent.Drawpage.Forms
main_frm = root_form.getByName("MainForm")
adate.year = 1990
adate.month = 7
adate.day = 4
main_frm.getByName("date_bx").date = adate
main_frm.getByName("date_bx").commit
End Sub
Declaration based on example for IsStruct function. See also API reference for UNO Date Struct.