I want to convert string timestamp to long. I receive string timestamp like this;
2019-03-29T19:26:36.272794Z -> it has 6 number after seconds(272794)
For this, I'm using this format in UpdateRecordProcessor;
${field.value:toDate("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", "GMT"):toNumber()}
But this solution does not give the correct solution. For example, result of above timestamp string is; 1553887868794. But this is equal to: 2019-03-29T19:31:08.794Z.
I guess, UpdateRecord uses SimpleDataFormat in the backend. But, as far as I know, SimpleDateFormat is only work with 3 number after seconds like above result.
How can I get correct result in UpdateRecord of Nifi?
Related
I have to get the max payment date on an invoice and I am having trouble with the date format. I do not need the max in this formula as I am using the format in a reporting tool that is pulling the max from what it finds for me.
Using "to_char({datefield},'mm/dd/yyyy')" works for displaying that date the way we would like BUT when you use summary function MAX it does not pull the correct date because it is looking at a string and not a date (it will think 12/3/21 is larger than 3/2/22).
Another thing I have tried is trunc - "trunc({datefield})" which gives us the correct max date but it changes the formatting. For example if the date prior to the formula being applied is "8/12/21 12:00:00:000" the trunc formula will display it as 12-08-21 which is horribly wrong.
Long story short is I need a way to change a date/time to date with the format of 'mmmm/dd/yyyy' WITHOUT converting it to a string with something like to_char. Thank you!!!!
A DATE is a binary data type consisting of 7 bytes representing: century, year-of-century, month, day, hour, minute and second. It ALWAYS has all of those components and it is NEVER stored with any (human-readable) format.
What you are seeing when a date is displayed is the client application you are using to access the database making a decision to be helpful to you, the user, and display the binary DATE provided by the database in a human-readable format.
If you want to change how the DATE is displayed then you either need to:
Change the settings on the client application that controls how it formats dates when it displays them to you; or
Change the data-type so that it is no longer a DATE (which does not have a format) to a data type where the values of the date can be formatted (such as a string). You can do this using TO_CHAR.
If you want to find the maximum then do it BEFORE applying the formatting:
SELECT TO_CHAR(MAX({datefield}),'mm/dd/yyyy')
FROM your_table;
I am using the NiFi ListAzureBlobStorage to get the available blob objects. The processor creates a flowfile for each object with the attributes containing the object metadata. I want to filter on the azure.timestamp attribute, but I do not know what the numeric value represents and how it relates to the NiFi's expression language date data type. I want to compare it with a known date so I need to convert it to a NiFi data-time variable first. How do I do this?
Thanks
According to the code it is already in "NiFi format" which means a Unix timestamp.
Since it represents the number of milliseconds passed since 1/1/1970, you can compare this and the other timestamp using regular number comparison operators.
example: ${azure.timestamp:ge(${now()})} - this will return true if the azure.timestamp is later(or equal) than the current timestamp(now).
If you'd like to compare it to another attribute you can do this:
${azure.timestamp:ge(${attribute.name})}.
If you'd like to convert a different date into a unix timestamp, you can use toDate and then toNumber, or to do the other way around, just use format.
I am using Elasticsearch 2.4 and I have a Groovy script. I have a field in my document say doc['created_unix_timestamp'] which is type integer and it holds Unix timestamp. In a search query's script, I am trying to get YYYYMM from that value.
For example, if doc['created_unix_timestamp'] is 1522703848, then in the scripting during a calculation, I want to convert it to as 201804 where first 4 digits are Year and last two are month (with padded 0, if required)
I tried:
Integer.parseInt(new SimpleDateFormat('YYYYMM').format(new Date(doc['created_unix_timestamp'])))
But it throws "compilation error" "TransportError(400, 'search_phase_execution_exception', 'failed to compile groovy script')" . Any idea how to get it work or what is the correct syntax?
A couple recommendations.
Reindex and make created_unix_timestamp a true date in elasticsearch. This will make all kinds of new querying possible (date range for example). This would be ideal.
If you can't reindex, then pull it back as an int from ES and then convert it to whatever you want client side, I wouldn't recommend pushing that work to the ES cluster.
As per the suggestion of Szymon Stepniak in above comment, I solved this issue by
(new Date(1522705958L*1000).format('yyyyMM')).toInteger()
Thanks and credit goes to Szymon Stepniak
Given "03/09/1982" how can we say it is which week day. In this case it will be "Tue".
Is it possible to get in a single query?
Thanks
You can convert this string into date object using ToDate(), then again into string with desired format using ToString(), and dont forget that Pig uses Java SimpleDateFormat class to deal with dates.
ToString( ToDate('03/09/1982','dd/MM/yyyy'), 'EEE' )
Date;Time;Global_active_power;Global_reactive_power;Voltage;Global_intensity;Sub_metering_1;Sub_metering_2;Sub_metering_3
16/12/2008;17:24:00;4.216;0.418;234.840;18.400;0.000;1.000;17.000
16/12/2008;17:25:00;5.360;0.436;233.630;23.000;0.000;1.000;16.000
16/12/2008;17:26:00;5.374;0.498;233.290;23.000;0.000;2.000;17.000
16/12/2008;17:27:00;5.388;0.502;233.740;23.000;0.000;1.000;17.000
16/12/2008;17:28:00;3.666;0.528;235.680;15.800;0.000;1.000;17.000
16/12/2008;17:29:00;3.520;0.522;235.020;15.000;0.000;2.000;17.000
16/12/2008;17:30:00;3.702;0.520;235.090;15.800;0.000;1.000;17.000
16/12/2008;17:31:00;3.700;0.520;235.220;15.800;0.000;1.000;17.000
16/12/2008;17:32:00;3.668;0.510;233.990;15.800;0.000;1.000;17.000
This is the sample data, i am really confused with the datatype to be used for Date and Time.
plese help,
You probably want to be looking at the TimeStamp datatype which has this format:yyyy-mm-dd hh:mm:ss
There is also a Date datatype which takes this format: YYYY-mm-dd
There isn't a seperate time datatype. If you can't change the sample data you probably want to load the dates as string and use udfs like unix_timestamp(string date, string pattern) then copy to result into a new table.