Talend- Empty string handling when parsing dates using tmap component - string

I have a job that loads a CSV into a MySQL table. The field I am paring to a date using the t-map component has empty strings for a few of the records. When parsing the string to date, I need to convert those empty strings to the current date. I've tried this expression in the tmap component with no luck. My field name is "Payroll_Pay_Date" Here is the expression:
row1.Payroll_Pay_Date equals("")?TalendDate.getCurrentDate():TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)
I've tried several itterations of this. Actually, what I really want to is to have the empty string be replaced with the "current date - 7 days" but I figure I would start with the above. Any advice would be much appreciated.

You could do this:
row1.Payroll_Pay_Date == null || row1.Payroll_Pay_Date.trim().isEmpty() ? TalendDate.getCurrentDate() : TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)
Here I first test if the string is null or if it's empty or containing only whitespaces, in which case I return the current date. Otherwise I parse the date.
To get the current date minus 7 days, you could do:
TalendDate.addDate(TalendDate.getCurrentDate(), -7, "dd")

Related

The expression is not valid after '>'

In Spotfire, I created a Cross Table. In the Cross table>Properties>Data>Limit data using expression:> I put the following:
Date([Discharge Date])=>'06-01-2019'
I get the error message "The expression is not valid after '>' on line 1 character 19"
I tried Date([Discharge Date])>'06-01-2019 but it still does not work
The code is Date([Discharge Date])=>'06-01-2019'
I hope to be able to use Date([Discharge Date])=>'06-01-2019' in the Cross table>Properties>Data>Limit data using expression:
enter image description here
I tried the Date(2019,6,1) but still got the error message.
enter image description here
According to the Spotfire Docs:
Creates a Date from a column or values. If a single argument is given,
the input column can be of type String or DateTime. If a String is
specified, the date must be written on a form that Spotfire can
recognize and all parts of the date (year, month and day) must be
present. If three integer arguments are given, then the first
argument is the year, the second is the month and the third is the
date in that month.
Example: Date([Column]) Date(2007, 05, 17)
Change your date formatting to [Discharge Date] >= Date(2019,06,01) and try again.

Oracle: Assistance in breaking apart a complex date string

I have a complex date string being read from a csv file. The format is unable to be processed by Oracle's TO_DATE function. Looking for an efficient method to break this string apart and return a date object, to insert into a DATE column. The suggested option of using TO_DATE with 'DD-MON-YY HH.MI.SS AM' does not work. Not variation of this will break up this particular string. Hence the need for a custom function. I have also tried with the 'HH.MI.SS.SSSSS AM' format which also does not work. I have found that if I drop the fractional seconds, it will work. If I run a regex to drop that portion, it should convert as expected.
The string is formatted as: 21-OCT-04 01.03.23.966000 PM
My initial thought is to break up by space first, resulting in three sub strings.
Then break the first substring by - and the second by ., and load the resulting pieces into a DATE object directly.
Is there a better method I could use?
Thank you, Allan
Use what you have, which is a timestamp literal, to create a timestamp, and then cast it "as date":
select
cast(to_timestamp('21-OCT-04 01.03.23.966000 PM', 'dd-MON-rr hh.mi.ss.ff AM') as date) dt
from dual;
DT
----------------------
2004/10/21 01:03:23 PM
(The output format depends on my specific session NLS_DATE_FORMAT, which I actually changed for this illustration to 'yyyy/mm/dd hh:mi:ss AM'.)

Stata: how to change a string variable to a date?

I'm new to Stata, and I'm wondering how can I change a string variable which contains a date to a date format.
The data in the variable looks like this:
yyyy-mm-dd
Should I first remove the dashes so that Stata can recognize the format in order to later use gen var = date() ?
Thank you for your help.
The Stata date function is smart about removing separator characters. See help datetime_translation under the section "the date function"
If your dates are in v1 and in the form yyyy-mm-dd you can specify the commands:
generate v2 = date(v1, "YMD")
format %td v2
The YMD is called a mask, and it tells Stata the order in which the parts of the date are specified. The second line will assign the variable the Stata daily date format, which means that when you look at that variable in the data, it will be shown in human readable form. The date is stored, however, as the number of days since January 1, 1960.
The best way to experiment with the date function is to use the display command. The first line will display an integer representing the number of days since January 1, 1960. The second line will display the date in a human readable format.
display date("2013-08-14", "YMD")
display %td date("2013-08-14", "YMD")
you can look here to see how to convert to data in Stata or do like this
tostring datedx, replace
generate str4 dxyr1= substr(datedx,1,4)
generate str2 dxmo1 = substr(datedx,6,7)
generate str2 dxda1 = substr(datedx,9,10)
destring dx*, replace
gen datedx1 = mdy(dxmo1, dxda1, dxyr1)

MATLAB - Only First Letter of String is Printing

I am having an issue printing a string in MATLAB (2012a) using the fprtinf command (and sprintf).
I have an array of 12 dates (numeric). I am converting them to strings using the following command:
months = datestr(data(:,1)-365,12); %Mar13 format
I obtain the following (and desired) output when I call the months variable:
Jan12
Feb12
Mar12
Apr12
etc..
The issue is when I call the fprintf or sprintf, say with the following code:
fprintf('%s', months(1))
I will only get the first letter of the month and not the full string. Any idea how to make it print the full string?
Thanks!
The resulting data type for your months variable is an NxM character array. You need to process it as a cell array of strings instead.
dates = num2cell(data(:,1)-365)
months = cellfun(#(x) datestr(x,12),dates,'UniformOutput',false)
fprintf('%s', months{1})
should get you what you want.
Simply change your call to
fprintf('%s', months(1, :))
datestr returns the string of each of the supplied dates on a separate row.
Alternatively you could use the cellstr function to convert the result to a cell array (this would also work with non fixed-length date formats like 'dddd')
months = cellstr(months);
fprintf('%s', months{1});

Sharepoint CAML Date query

im getting different results based on the date i use to search on.
Here are the 3 records i want to display, their values for EVENTDATE, and ENDDATE are as follows
1, 2009-08-11T00:00:00Z, 2009-08-14T23:59:59Z
2, 2009-08-11T00:00:00Z, 2009-08-14T23:59:59Z
3, 2009-08-14T20:00:00Z, 2009-08-14T22:00:00Z
When i search for a time between EventDate and EndDate
- 2009-08-14T20:00:00Z, 2009-08-14T22:00:00Z
= i get rows 1,2
- 2009-08-14 T20:00:00Z, 2009-08-14 T22:00:00Z
= i get rows 3
Why does adding a space between the date and time give me a diff result? The entries into the list are the same, the return results dates are the exact same format.
Although the ISO 8601 standard specifies that a space to either side of the T is valid, I would guess that the CAML parser only accepts non spaces. And what you are seeing is a side effect.

Resources