cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Arkawa
Level III

How to script date of the current month for data compilation

Hi all,

 

I have the following code which does not work :

// Current date
aujourd'hui = Text(Today(),"00000000");

// Obtain the month number format "MM"
numero_mois = Text(Month(aujourd'hui), "00");

// Obtain the year number - 1 format YYYY
numero_annee = Text(Year(aujourd'hui) - 1, "0000");

// Concatenate the result
date_debut_mois_actuel_Y = ("01" || numero_mois || numero_annee);

// Show the result
Show(date_debut_mois_actuel_Y);

dt << Select Where(:Date < date_debut_mois_actuel_Y);
dt << Delete rows;

The objective is to select all rows from dt (Data Table) for which the date is < 01/current month/current year -1, and to delete them.

 

I understand the error, that I cannot concatenate other elements than character, but how can I obtain the date under the format 01/10/2022 (expecation of today for example), without go back to the code and change manually the date.

 

The error message is : argument should be character at row xxx in access or evaluation of 'Concat' , Bad Argument( numero_mois ), "01" || /*###*/numero_mois || /*###*/numero_annee/*###*/

 

Up to date the code is (to be modified manually each month) : 

dt << select where(:name("date") < informat("01102022","DDMMYYYY"));
dt << Delete rows;

Thank you very much !

 

Best regards

10 REPLIES 10
jthi
Super User

Re: How to script date of the current month for data compilation

If you just want first day of month, use Today() to get the todays date and then Month and Year with Date DMY to build your date

now = Today();
first_of_month = Date DMY(1, Month(now), Year(now));
Show(As Date(first_of_month));
-Jarmo