Convert string of length 8 to *EUR date for comparing - datetime

I want to convert a string of length 8 to a date type for comparing it. The string is formatted as DDMMYYYY (*EUR).
It has no periods for seperating the days from months and months from years. If I input a value like '01012018' to the %date BIF the compiler tells me that the expression is too short for the format *EUR:
D dateEUR s d datfmt(*EUR)
C eval dateEUR = %date('01012018':*EUR)
My previous way to compare to two dates was to take both of them, store them in datastructues, reorder the date with subfields and take the resulting, reordered date from a overlaying subfield.
Has anyone a idea of how to convert the 8A string to a DATE type in RPGLE?

The format you specify will depend on whether or not you store the date separators. If your date is in a 10-byte character field as DD-MM-YYYY (with the dashes), this is again EUR format:
%date(alpha_date : *eur)
If you don'tt need standard separators with your date (DDMMYYYY in an 8-byte character field) simply append the number zero (0) to the end of the format name:
%date(alpha_date : *eur0)

Related

controlM variable for YYYYMM?

I'm using ControlM and in a command, I would like to find a variable that gives me the date in this format : YYYYMM
I found there is %%$DATE variable but it gives YYYYMMDD
Thanks for you help
It is possible to define and concatenate a variable that will represent the date in such a format.
These are available:
Day DD, %%DAY,
Month MM, %%MONTH,
Year YY, %%YEAR,
Year YYYY, %%$YEAR
Prefer %%$OYEAR AND %%OMONTH over %%$YEAR and %%MONTH
I suggest using the variables %%$OYEAR and %%OMONTH over %%$YEAR and %%MONTH. The reason is that date variables beginning with O refer to processing dates and do not necessarily coincide with the system date. For this case you could use any of the following options:
1. YYYYMM = %%$OYEAR.%%OMONTH
2. YYYYMM = %%SUBSTRING %%$ODATE 1 6
The $ symbol preceding the variable %%$OYEAR or %%$ODATE indicates that the year is returned in 4-digit format, instead of OYEAR or ODATE which print the year with only 2 digits.
The dot (.) character is used for concatenate variables.
For example: For the order day May 29, 2020.
1. %%$ODATE would print 20200529
2. %%ODATE would print 200529

How to determine the correct argument for origin in as.Date, R

I have a data set in R that contains a column of dates in the format yyyy/mm/dd. I am trying to use as.Date to convert these dates to date objects in R. However, I cannot seem to find the correct argument for origin to input into as.Date. The following code is an example of what I have been trying. I am using a CSV file from Excel, so I used origin="1899/12/30 based on other sites I have looked at.
> as.Date(2001/04/26, origin="1899/12/30")
[1] "1900-01-18"
However, this is not working since the input date 2001/04/26 is returned as "1900-01-18". I need to convert the dates into date objects so I can then convert the dates into julian dates.
You can either is as.Date with a numeric value, or with a character value. When you type just 2001/04/26 into R, that's doing division and getting 19.24 (a numeric value). And numeric values require an origin and the number you supply is the offset from that origin. So you're getting 19 days away from your origin, ie "1900-01-18". A date like Apr 26 2001 would be
as.Date(40659, origin="1899-12-30")
# [1] "2011-04-26"
If your dates from Excel "look like" dates chances are they are character values (or factors). To convert a character value to a Date with as.Date() you want so specify a format. Here
as.Date("2001/04/26", format="%Y/%m/%d")
# [1] "2001-04-26"
see ?strptime for details on the special % variables. Now if you're read your data into a data.frame with read.table or something, there's a chance your variable may be a factor. If that's the case, you'll want do convert to character with'
as.Date(as.character(mydf$datecol), format="%Y/%m/%d")

How to add months to a date in yyyymm format

I have two columns in my table one is having a date in yyyymm format and other column has some integer values between 1 to 50. How can I add these two fields and get a date value?
For example: 201402 + 12 should give me 201502 as an answer!
I assume you don't really have a DATE column but a varchar column that stores a month specification in the format yyyymm.
If you want to make use of Oracle's date arithmetic you first need to convert this "month" into a real date.
Something like this:
select to_char(add_months(to_date('201402', 'yyyymm'), 12), 'yyyymm')
from dual;
You will need to replace the character literal '201402' with a reference to your column.

convert string to time in r

I have an array of time strings, for example 115521.45 which corresponds to 11:55:21.45 in terms of an actual clock.
I have another array of time strings in the standard format (HH:MM:SS.0) and I need to compare the two.
I can't find any way to convert the original time format into something useable.
I've tried using strptime but all it does is add a date (the wrong date) and get rid of time decimal places. I don't care about the date and I need the decimal places:
for example
t <- strptime(105748.35, '%H%M%OS') = ... 10:57:48
using %OSn (n = 1,2 etc) gives NA.
Alternatively, is there a way to convert a time such as 10:57:48 to 105748?
Set the options to allow digits in seconds, and then add the date you wish before converting (so that the start date is meaningful).
options(digits.secs=3)
strptime(paste0('2013-01-01 ',105748.35), '%Y-%M-%d %H%M%OS')

Legal characters in ISO sortable date format

What are the valid characters for an ISO date? I know of 0 through 9, -, :, T and Z. Are there any more?
I obtain this sortable date format in .NET with .NET's XML serialization and like this:
var stringDate = myDateTime.ToString("s");
It looks like you can also have a W as part of the ISO week date.
You can have a , or . when dealing with decimal fractions that are added to a time element (See the times section here):
To denote "14 hours, 30 and one half minutes", do not include a
seconds figure. Represent it as "14:30,5", "1430,5", "14:30.5", or
"1430.5".
+ is valid when using them with UTC offsets such as 22:30+04 or 1130-0700.
Durations can use a bunch of letters such as P, Y, M, W, D, T, H, M, and S. They are a component of time intervals and define the amount of intervening time in a time interval.
Time intervals are the last one and can use / to split a start and end time.
It looks like the default format when using the s format string on a datetime is yyyy-MM-ddTHH:mm:ss", so the only valid characters in this case would be 0 to 9, -, : and T. The other characters above are part of the ISO 8601 standard which the sortable date/time pattern follows, but might not be applicable unless you deal with a different format string or culture.

Resources