substring datastage job parameter - datastage

I am executing Unix command in Datastage as follows:
/unixScriptDir/remove_terms.ksh /SourceDir/ 20200225
I have existing parameters in the DataStage, so my command will looks like this, except Date parameter in the different format than I need for this script – EnclRerunDt is in YYYY-MM-DD format, I need to substring it to the following format: YYYYMMDD. I am not sure how to do that.
I tried the following but DS does not understand: [#EnclRerunDt#,1,4]
#unixScriptDir#/remove_terms.ksh #SourceDir# [#EnclRerunDt#,1,4][# EnclRerunDt#,6,2][# EnclRerunDt#,9,2]

Substring function is in following format in DataStage
field[start, length]
So try something like this
#EnclRerunDt#[1,4] : #EnclRerunDt#[6,2] : #EnclRerunDt#[9,2]

Related

Azure Data factory not able to convert date format

I'm trying to get DAYID as string in format YYYYMMDD, however its not working correctly.
I have a timestamp field, I take first 10 characters and convert it into date (working correctly)
toDate(substring(EventTimestamp,1,10))
-- 2021-03-24
However when I try to convert to string using below expression, I;m getting wrong answer. I;m getting the Day as 83.
toString(toDate(substring(EventTimestamp,1,10)),'YYYYMMDD')
--20210383
Date format characters are case-sensitive as per this answer here, so use yyyyMMdd instead.
An example using formatDateTime:
#formatDateTime(utcnow(), 'yyyyMMdd')

Unix string to date conversion, what is wrong

I know the topic has already emerged and some of the posts give a good summary like the one here: Convert string to date in bash . Nevertheless, I encounter a problem presented below with an example I should solve:
date +'%d.%m.%y' works as desired and returns 05.12.20 but the inverse operation I should use to convert strings to date fails:
date -d "05.12.20" +'%d.%m.%y'
date: invalid date ‘05.12.20’
and this is exactly what I need. The Unix date formatting I have also checked on https://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/ but it seems to be in line with that. What is the problem? I also tried to supply time zone indicators like CEST but they did not solve the problem.
Try
date -d "05-12-20" +'%d.%m.%y'
UNIX date expects either - or / as a date separator.
However, if your input really must be in the format "05.12.20" (i.e. using .), then you can convert it to the format expected by UNIX date:
date -d `echo "05.12.20" | sed 's/\./-/g'` +'%d.%m.%y'

Getting date format from string

I have what I think it's a simple question.
I have a file named like this: 'prec/CHIRPS/P_CHIRPS.v2.0_mm-day-1_daily_2020.01.01.tif' and you can see it has a date within.
I've used successfully the package datefinder to extract the date from that string, but now what I want to do it's actually get the format from which datefinder read that date. That means that I want an output to be '%Y.%m%.d%' so I can use it to write a file with that same date format.
This is for example to be able to use whichever format of date and whichever file name I have, extract both the date and its format, and finally rewrite something like 'this is just an example of the file name with the date 2020.01.01'.
Thanks!!

In RPG, use a date, in *job format from a file

I'm trying to convert, in a RPG program, a date from a file (it's from the DSPJRN command, so the field si 6 numeric, in JOB format).
I want to use it as a date in my program, but I can't achieve it correctly.
I have tried to describe a field with type "D": date, keyword datfmt(*job) to convert the value from the file, but datfmt(*job) is incorrect (error RNF0612)
I have tried to retrieve the job Date format from a CLP program with RTVJOBA DATFMT(&FMT), and use the variable in RPG to convert the date like this
eval ztJODATE = %date(JODATE:FMT)
but it doesn't compile : error RNF0606 . I think that I can't use a variable for the format in the %date built-in function.
Is this a way to do what I want, or am I forced to transform the date value in SQL before using its value in RPG?
PS: I don't want to hardcode the format in my RPG program!
You can specify *JOBRUN for %DATE.
eval ztJODATE = %date(JODATE:*JOBRUN)
Note that RPG retrieves the job date format during initialization of the module, so if you change the job date format while the program is running, RPG will not understand the date.
Rather than using DSPJRN to an outfile, the recommended way to retrieve and process journal entries would be to use one of the programatic interfaces provided by IBM i.
Retrieve Journal Entries (QjoRetrieveJournalEntries) API
QSYS2.DISPLAY_JOURNAL() stored procedure
You could also use a *TYPE3 or higher format for the output file. Rather than the separate job formatted data & time fields, there's a single char(26) system timestamp field.
Having said that, there is a Convert Date and Time Format (QWCCVTDT) API that accepts '*JOB' as an input format specifier..

logstash reformat dates at OUTPUT time

I'm outputting to CSV and I'd like my dates in ISO8601 format, such as 2014-04-02T19:21:36.292Z, but I keep getting dates like Mar 27 2014 17:56:33 in my csv.
I'm fine to create a second intermediate string variable to do the formatting, but it yields the same result.
I see that there's a "sprintf" function in Logstash, but it seems you can do EITHER variable references OR date formats (which I assume will get the current system date time), but I don't think you can do both. I other words, I don't think it lets you apply a date format to an existing date variable, or if it does I'm not sure what the syntax would be.
Plenty of false hits on Google and stack, but all are about parsing.
Ironically stdout happens to output in the format I want, using stdout { debug => true codec => "rubydebug"}. Maybe that could somehow help in my case, not sure? Although other folks might want some other arbitrary format.
Try this one. Add a new "date" field then output to csv.
filter {
ruby {
code => '
require "time"
event["date"] = Time.parse(event["#timestamp"].to_s).iso8601;
'
}
}