Macro to adjust date on input file

Melissa_21551
Melissa_21551 New Altair Community Member
edited January 2018 in Community Q&A

I am using the Monarch Server Automator version 14.1 to run a process.  This process uses a project that looks for an import file with naming that looks like this:

 

OTD.DRAFT.TAPE1801042204 

the numbers are the 2 digit year-month-day-time. 18-year 01-month 04-day 2204-time   I have the project set to look for:

 

OTD.DRAFT.TAPE&[yy]&[mm]&[dd]*  this allows it to pick up a file that matches todays date.

 

What I need is it to pick up a file with yesterdays date.  I have tried adjusting the macros by -1 from each

 

OTD.DRAFT.TAPE&[yy-d]&[mm-d]&[dd-d]*    This ended up working but picked up everyday before today that was in the file

 

I also tied just -1 on the day  OTD.DRAFT.TAPE&[yy]&[mm]&[dd-1]*  This picked up everyday before today that is in the same month and year

 

How can I adjust the macro to only pick up yesterdays file?  I do need to take into consideration that on 01-01-19 I need to pick up 12-31-18

 

Thank you!

Tagged:

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2018

    To pick up previous day file using a macro use the following syntax:

    previous day: &[yy]&[mm]&[dd.-1d]

    Previous month: &[yy]&[mm.-1m]&[dd]

    Previous year: &[yy.-1y]&[mm]&[dd]

    However when the month changes, the syntax should be &[yy]&[mm.-1m]&[dd.-1d]

    When the year changes, the syntax should be &[yy.-1y]&[mm.-1m]&[dd.-1d]

    I suggest you copy the input file to a folder, and use a wild card character, e.g OTD.DRAFT.TAPE*

    Regards

    Mo

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2018

    To pick up previous day file using a macro use the following syntax:

    previous day: &[yy]&[mm]&[dd.-1d]

    Previous month: &[yy]&[mm.-1m]&[dd]

    Previous year: &[yy.-1y]&[mm]&[dd]

    However when the month changes, the syntax should be &[yy]&[mm.-1m]&[dd.-1d]

    When the year changes, the syntax should be &[yy.-1y]&[mm.-1m]&[dd.-1d]

    I suggest you copy the input file to a folder, and use a wild card character, e.g OTD.DRAFT.TAPE*

    Regards

    Mo

    Mo,

     

    What would be really great here would be an option to work with the current date, as one can in Monarch for example, and specify a number of days, months, years, or whatever to change it by. Then convert the result to the format used to select the report.

     

    Any possibility of proposing that to the developers?

     

    I guess it could be scripted or processed separately (based on a User input field at run time?) and the result brought in somehow but so much easier if it could be applied directly.

     

     

    Melissa,

     

    If it is safe to assume that all of the reports in the folder with name the same other than the date part  are consistent for processing by this routine (I am assuming you may have several reports here in some situations but realise you might just be needing a formula that picks up "yesterday's" file for processing today)  .... then you also have the option of processing every file and filtering the results.

     

    If you need to allow for, perhaps, deferred processing because reports are not presented each day of a weekend,say, or systems have been taken out of action for maintenance or some other example, then running a mass process once for a black of reports and filtering the results for output may be a good approach anyway. It would also provide for easy recovery in the event that something goes wrong with the process somewhere and the auto run fails or the distribution fails (email system down for example) and re-running would be the simplest way to resolve things.

     

    Just a few thoughts to add to possibilities.

     

     

    Grant

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2018

    Mo,

     

    What would be really great here would be an option to work with the current date, as one can in Monarch for example, and specify a number of days, months, years, or whatever to change it by. Then convert the result to the format used to select the report.

     

    Any possibility of proposing that to the developers?

     

    I guess it could be scripted or processed separately (based on a User input field at run time?) and the result brought in somehow but so much easier if it could be applied directly.

     

     

    Melissa,

     

    If it is safe to assume that all of the reports in the folder with name the same other than the date part  are consistent for processing by this routine (I am assuming you may have several reports here in some situations but realise you might just be needing a formula that picks up "yesterday's" file for processing today)  .... then you also have the option of processing every file and filtering the results.

     

    If you need to allow for, perhaps, deferred processing because reports are not presented each day of a weekend,say, or systems have been taken out of action for maintenance or some other example, then running a mass process once for a black of reports and filtering the results for output may be a good approach anyway. It would also provide for easy recovery in the event that something goes wrong with the process somewhere and the auto run fails or the distribution fails (email system down for example) and re-running would be the simplest way to resolve things.

     

    Just a few thoughts to add to possibilities.

     

     

    Grant

    Melisa,

    I agree with Grant and the previous date macro can be enhanced.

    I find another solution that you can try,

    Create a Standard project in the Automator and add three input files as listed below (change path)::

    ' covers input file within each month

    \\WIN201664A\C$\Datawatch\Automator\STD\DateMacro\OTD.DRAFT.TAPE&[yy]&[mm]&[dd.-1d]

    ' covers input file that has the month end date and the current date is first day of the new month

    \\WIN201664A\C$\Datawatch\Automator\STD\DateMacro\OTD.DRAFT.TAPE&[yy]&[mm.-1m]&[dd.-1d]

    ' covers input file that has last date of last month of the previous year and the current date is first date of the first month of the new year

    \\WIN201664A\C$\Datawatch\Automator\STD\DateMacro\OTD.DRAFT.TAPE&[yy.-1y]&[mm.-1m]&[dd.-1d]

    Set the File existence criteria option to 'not required'

    image

    Create a Standard process, either schedule it or monitor for the OTD.DRAFT.TAPE* input file name.  The process should be able to fins at least a file that meets the above macros.

    The only think is, if there is only one file is in the folder, and input distribution is configured, the process runs successfully with distribution error, but no process failed alert will be generated.

    Regards

    Mo

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2018

    Hello,

     

    I use the yesterday's date macro for most of my processes in Automator as we need the end of day file for yesterday. The macro is what you have above but with a period in before the "-d", not sure if you have that in Automator or that just wasn't typed here.

    OTD.DRAFT.TAPE&[yy.-d]&[mm.-d]&[dd.-d]*  

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited January 2018

    Hello,

     

    I use the yesterday's date macro for most of my processes in Automator as we need the end of day file for yesterday. The macro is what you have above but with a period in before the "-d", not sure if you have that in Automator or that just wasn't typed here.

    OTD.DRAFT.TAPE&[yy.-d]&[mm.-d]&[dd.-d]*  

    Yes I had the period (.) before -d in the Automator.

    I tired your syntax OTD.DRAFT.TAPE&[yy.-d]&[mm.-d]&[dd.-d]* and also OTD.DRAFT.TAPE&[yy.-1d]&[mm.-1d]&[dd.-1d]* and both syntaxes worked fine.

    So one input using the above syntax will work for previous day.

    Regards

    Mo