Saving a date field value into physical file - database

I have a date field which accepts system date in AS400
Display file contains a date field by *DATE
I have a physical file that has a date column.When i try saving the other fields of my screen onto this physical file,i would also like to save this system date.
But i am unable to add a field name to this inbuilt Date function.
How else can i have a date field in my display screen that will automatically accept system date and have format in DD/mm/yy format for input but internally in database it must save it as yy/mm/dd.
For the purpose of having this internal conversion in my database of date format,i have initialized a date field named "date" of length 6,Packed decimal,0 decimal position.
Please guide how to save system date from screen in this format into the physical file.
Reedited:
I have a PF of grade received date defines as follows.(Its DDS)
0004.00 A GRCVDT 6P 0
I refrain to use 'L' data type for date as i want to perform date conversion as i have above explained.

On a display file, *DATE is output-only. It cannot be read by a program.
It sounds like the database table has a decimal field called DATE; not a date field called DATE. Using a date data type will make date manipulation so much easier - see Dennis' answer for advice on that. If it is impossible to use a date data type, and you must use a decimal data type to hold the date value, look at the RPG TIME operation code. That will allow you to extract the current system date into a program variable. The exact format the date will be returned depends on your job date format setting. (WRKJOB to see that). You can use a data structure and a series of EVAL statements to rearrange the date elements if you need to.
EDIT Code sample to convert EUR to YYMMDD
d eur ds qualified
d ddmmyy 6s 0
d dd 2s 0 overlay(ddmmyy: 1)
d mm 2s 0 overlay(ddmmyy: 3)
d yy 2s 0 overlay(ddmmyy: 5)
d ymd ds qualified
d yymmdd 6s 0
d yy 2s 0 overlay(yymmdd: 1)
d mm 2s 0 overlay(yymmdd: 3)
d dd 2s 0 overlay(yymmdd: 5)
c/free
eur.ddmmyy = 020812;
ymd.yy = eur.yy;
ymd.mm = eur.mm;
ymd.dd = eur.dd;
dsply ymd.yymmdd;
*inlr = *on;
/end-free

Is this file created via DDS or SQL? If DDS, then please add the field of your choice to the DDS specs, and specify a Data Type of L:
A MYDATE L
Then use CHGPF, specifying the source file and member name; the system will add the new column.
CHGPF FILE(MYLIB/MYFILE)
SRCFILE(MYSRCLIB/MYSOURCE)
SRCMBR(MY_MBR)
Even if your file is DDS described, you could add the date column by using an SQL statement like:
alter table mytable add column mydate date not null default
(But of course, if you do that, you cannot recreate the file from DDS anymore without losing the new column)
Then in your program, just before the WRITE to the data, do:
mydate = %date
There are many assumptions here: you are using ILE, you know how to modify and recompile the program, you are using free form or can translate the "variable = value" syntax above, ...)
There are also other ways to get the system date into a file without your program having to do anything special; we actually need to know more about the application in order to help much beyond this high-level advice.

Related

Formatting logic app expression for DateTime

I am generating a file for export with the file name utcnow in the logic app expression which returns a value like this
utcNow()- "2020-06-01T15:41:15.5103915Z"
I want to convert it like "20200601154151" that means I need to remove some characters like" -","T" and millisecondsfollwed by Z,
I tried few combination of string format and I am not getting it right hoping you guys to help me.
Thanks,
There are many options for custom date formats. Here is a simple guide:
yyyy = Year (2020)
MM = Month (06)
dd = Day (01)
HH = Hour (15)
mm = Minute (41)
ss = Second (15)
Construct a format string (ex: yyyyMMddHHmmss) based on your requirements and pass it to formatDateTime:
formatDateTime(utcNow(), 'yyyyMMddHHmmss')
The resulting value will be '20200601154115'. There are many additional options at the link above.

CSV file format change

I am using a flat file data provider in SSIS to import data from an external system. I don't have any control over the file, it is pushed out on a weekly basis, and I pick it up from a common folder.
The first two columns of the CSV are dates. Part of the way through the file, the date format has changed from date to numeric as follows:
Service_Date, Event_Datetime
2018-04-30,2018-04-30 21:18
43220,43220.92412
As you can see, the format changed from date to numeric. Other date columns not shown here also have changed.
Obviously, this is breaking the data flow task.
Aside from going into Excel and saving the CSV with the proper column format, is there any way within SSIS can convert on the fly so that the job doesn't fail and require manual intervention?
These data values 43220,43220.92412 are called date serials, you can get the date value in many approaches:
(1) Using A derived Column
You can convert this column to float then to datetime using a derived column:
(DT_DATE)(DT_R8)[dateColumn]
References
convert Excel Date Serial Number to Regular Date
Is there a better way to parse [Integer].[Integer] style dates in SSIS?
(2) Using a script component
You can use DateTime.FromOADAte() function, as example: (code in VB.NET)
If Row.ServiceDate_IsNull = False AndAlso String.IsnullOrEmpty(Row.ServiceDate) Then
Dim dblTemp as Double
If Double.TryParse(Row.ServiceDatemdblTemp) Then
Row.OutputDate = DateTime.FromOADate(dblTemp)
Else
Row.OutputDate = Date.Parse(Row.ServiceDatemdblTemp)
End
End If
Reference
SSIS Script Task - VB - Date is extracting as INT instead of date string
I was able to solve the problem using a variation of the derived column. This expression would catch the column obviously formatted as a date, and convert it to a date, otherwise it converts the date serial to a float first, then to a date
FINDSTRING(Date_Service,"-",1) != 0 ? (DT_DATE)Date_Service : (DT_DATE)(DT_R8)Date_Service

Error scatter plot time vs wind speed (data from a table) MATLAB

I am trying to make a simple scatter plot in MATLAB with time on the x-axis and wind speed on the y-axis. I loaded in my data from a text file as a table and then tried to use table2array to plot since it needs numeric values not table data. I also tried using double and got another error.
Error Message: Error using scatter (line 55) Input arguments must be numeric or objects which can be converted to double.
Error in windconversions (line 18) scatter(time,wnd_TS)
I'm not sure if having the times as strings will also be an issue.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%A = table2array(T)
date = T(:,1);
time = T(:,2);
wnd_TD = T(:,10);
wnd_TS = T(:,11);
table2array(wnd_TS);
table2array(time);
%double(wnd_TS);
scatter(time,wnd_TS)
A simpler way to access the data contained within the table is to use the dot notation, as T.VarN, where N is the number of the column you are interested in.
In your code you are using only 'time' for the plot, however this consists of hours, minutes and seconds only. I suspect that for your graphical analysis you require the combination of both the date and the hours.
It is possible to perform arithmetic addition on datetimes, however it is required that the two variables have the same format. By converting both dates to format 'MM/dd/yyyy HH:mm:SS' you are actually modifying the data of the variables. However, as stated in the documentation:
Since the data in the first column of the file ("date") have no time information, the time of the resulting datetime values default to midnight. Since the data in the second column of the file ("time") have no associated date, the date of the datetime values defaults to the current date.
When you add the variables date and time together together, you can add the date ('MM/dd/yyyy') of date to the time ('HH:mm:SS') of time.
An example of datetime conversion and addition follows.
Variables date and time before conversion:
date = 05/04/2011
time = 00:00:42
After conversion:
date = 05/04/2011 00:00:00
time = 06/01/2018 00:00:42
Adding the two:
05/04/2011 00:00:42
The code which reads the table and plots the scatter graph:
%Read table.
T = readtable('allunderway.txt', 'HeaderLines', 2);
%Access data of interest from table.
date = T.Var1;
time = T.Var2;
wnd_TS = T.Var11;
%Convert variable time to datetime.
time = datetime(time,'Format','HH:mm:SS');
%Add hours, minutes and seconds to variable date.
date = datetime(date,'Format','MM/dd/yyyy HH:mm:SS');
%Add month, day and year to variable time.
time = datetime(time,'Format','MM/dd/yyyy HH:mm:SS');
%Combine date and time variables.
fullt = date+timeofday(time);
scatter(fullt,wnd_TS);
The output of the code is the required scatter graph:
You can find more information on combining date and time from separate variables here.
Why do so much extra work. You could have simply used scatter(datenum(T.time),T.wnd_TS). That should do the job and save all the extra effort.

Timestamp format modification in Oracle 10g [duplicate]

I have a function which should accept date in a format DD-MON-YY and should display in the format DD-MM-YYYY. The function I have created is :
create or replace function PRINT_IT(abc date)
RETURN DATE
IS
v_date DATE;
BEGIN
if regexp_like(abc,'^[0-9]{2}-[a-z]{3}-[0-9]{2}$')
then
v_date := TO_DATE(abc,'DD-MM-YYYY');
else
dbms_output.put_line('wrong format');
end if;
dbms_output.put_line('The date is ');
return v_date;
END PRINT_IT;
but the value returned is always wrong date format!!
No, it's not. Your date is being output in the format specified by your NLS_DATE_FORMAT. I you want to display if differently then change this parameter for your session:
alter session set nls_date_format = 'dd-mm-yyyy'
Note the word display. That's all this does. That's all you should consider doing. The way a date is displayed in no way effects the way it is stored.
More normally you might use TO_CHAR() with an appropriate format model to display a date, i.e. to_char(my_date, 'dd-mm-yyyy'). It will no longer be a date but a character.
It doesn't look like you want to display a date as you've said. You're returning the value from your function, in which case I would stick with what you have. You only need to transform a date into an appropriate format for display when taking it out of the database, always store it as a date in the database. This in turn means that it doesn't matter what it looks like when stored in the database, merely that it is actually a date.

date comparison in oracle for the year ends with 00

The date stored in my database is 01-01-1900 for field emp_doj(Data Type DATE).
But while retrieving the data, the value is 01-jan-00, even though formatted with dd-mm-yyyy.
I am comparing retrieved date field with some other date in SQL query.
select *
form persons
where per_join = to_date(to_char(i.emp_doj,'DD-MM-YYYY'),'DD-MM-YYYY')
Here the value of to_date(to_char(i.emp_doj,'DD-MM-YYYY'),'DD-MM-YYYY') results in 01-01-00, instead of 01-01-1900
I suspect it's your default NLS settings for the IDE you are using that is merely displaying the dates with a two digit year. Oracle does not store dates in any specific format. It stores them in a binary format internally.
Therefore I suggest you check the settings for your IDE and/or database and you will see the NLS date format set to DD-MM-YY, alter this and set it to DD-MM-YYYY and you will see the dates as you wish to see them.
As for your query, why use TO_CHAR and then TO_DATE? If emp_doj is a date field and per_join is also a date then just compare them directly for equality. If you are trying to cut the time portion off your emp_doj values then just use TRUNC().
For examples and reference on NLS: http://www.orafaq.com/wiki/NLS
More here: http://www.oracle.com/technetwork/database/globalization/nls-lang-099431.html
select to_char(emp_doj,'dd-mm-yyyy') from yourtable
I have got some temporary solutions it currently works for me, I simply changed my select query to
select *
form persons
where to_date(per_join,'DD-MM-YYYY')= to_date(i.emp_doj,'DD-MM-YYYY')

Resources