Parsing date in Pascal - date

what's the better way of parsing date in Pascal than manually parsing character after character?
Date should be in mm.dd.yyyy format.

Depends on the compiler used. If you use Delphi have a look at trystrtodate, or (if with a recent Free Pascal) try dateutils.scandatetime

If you're using Turbo Pascal, then the only thing you can do is check the string character by character.
Or, you can create a record:
type
dater = Record
month: byte;
day : byte;
year: integer;
End;
var mydate: dater;
Thus, knowing the format (mm.dd.yyyy) you can easily validate it.
Access the values easily mydate.month, mydate.day, mydate.year.

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')

Is there a way to remove symbol from date in x++?

I am importing fields from Excel to my journal. The problem is - it does not import dates that have a dot or slash in end of the date, like 01.01.2020. The field is just empty.
I am trying to find a way to remove teh last symbol, if it exists. I tried str test = date2Str(_country, 123, -1, -1, -1, -1, -1, -1);, but it will take data that does not have a dot or slash in the end. It could be easy to work with date if it was a string, but I am failing to convert it to a string because of that dot or slash in end of the date...
It only converts 01.01.2020 format but it does not convert 01.01.2020. Any suggestions would help a lot. Thanks.
Option 1
Clean up the source data. I cannot image that Excel stores proper date values with a trailing . or /.
Option 2
How are you fetching the Excel values? Does your third party (?) solution offer a method like myCell.getDateValue() that returns a date type instead of a string type?
Option 3
You could apply a simple substr() with length=8 to trim of any trailing characters. The line of code below works for me.
date d = str2Date(subStr('01.01.2020.', 1, 8), 123);

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..

How to format input for SAS's MONYY format

I currently have a dataset with dates in the format "FY15 FEB". In attempting to format this variable for use with SAS's times and dates, I've done the following:
data temp;
set pre_temp;
yr = substr(fiscal,3,2);
month = substr(fiscal,6,length(fiscal));
mmmyy = month||yr;
input mmmyy MONYY5.;
datalines;
run;
So, I have the strings representing the year and corresponding month. However, running this code gives me the error "The informat $MONYY was not found or could not be loaded." Doing some background on this error tells me that it has something to do with passing the informat a value with the wrong type; what should I alter in order to get the correct output?
*Edit: I see on the SAS support page for formats that "MONYYw. expects a SAS date value as input;" given this, how do I go from strings to a different date format before this one?
When you see a $, it means character value. In this case, you're feeding SAS a character value and giving it a numeric format. SAS inserts the $ for you, but there is no such format in existence.
I'm going to ignore the datalines statement, because I'm not sure why it's there (though I do notice there is no set statement). You might have an easier time just changing your program to:
data temp;
yr = substr(fiscal,3,2);
month = substr(fiscal,6,length(fiscal));
pre_mmmyy = strip(month)||strip(yr);
mmmyy=input(pre_mmmyy,MONYY5.);
run;
you can also remove the "length(fiscal))" from the substring function. The 3rd argument to the substring function is optional, and will go to the end of the string by default.

Convert a formatted date string to a date value in XPath

How can I convert a date contained in a string into a date value with XPath?
I got the string by formatting a date value with fn:format-date, and now I want the date value from the formatted string.
Thank you,
You can use EXSLT's date:date(string). It is implemented in most XSLT processors but also as a pure XSLT function.
Documentation: http://www.exslt.org/date/functions/date/index.html.