What transformer can I use to put a date into YYYY - MM - DD format with no time format in final result? - webmethods

I just started using webMETHODS today and need to transform a date input value that comes in like this.
Example:
yyyy-mm-dd hh:mm:ss:hh
I need just the date portion of this variable and am currently using pub.date:formatDate which will crash my flow service.
What should I be using?

An alternative would be to use pub.date:dateTimeFormat, which allows you to set an input pattern, for example dd.MM.yyyy hh:mm:ss.

pub.date:formatDate is used to convert a date input to a string output based on a string pattern.
Here you are trying to convert a string input to a string output.
You have to do the following:
a.
First convert the string (Process_date_orig_str) to date format (Process_date_dt)
b. Then use the date (Process_date_dt) to the required string format using pub.date:formatDate to get (Process_date_new_str)
Note: You will have to create your custom java service to convert string to Date.

I played around with this for practise. The 'correct' answer is what Christian Strempfer posted - this is what pub.date:dateTimeFormat is meant to do: transform beween datetime string formats. I'm not sure about your date pattern though - try currentPattern=yyyy-MM-dd HH:mm:ss.SS and newPattern=yyyy-MM-dd
A 'good hacky approach is using pub.string:subString (positions 0 and 10) to simply hack the end off the input string. You can also try regexs -- pub.string:replace, useRegex=true, searchString=^(.{10}).*, replaceString=$1. (searchString=^(.{10}) should also work, but it doesn't)

Related

Snowflake interpreting timestamp wrong?

I'm loading a bunch of semi-structured data (JSON) into my database through Snowflake. The timestamp values in the entries are javascript timestamps that look like this:
"time": 1621447619899
Snowflake automatically converts this into a timestamp variable that looks like this:
53351-08-15 22:04:10.000.
All good so far. However, I think that the new timestamp is wrong. The actual datetime should by May 19, 2021 around 12pm MDT. Am I reading it wrong? Is it dependent on the timezone that my Snowflake instance is in?
When comparing the following options manually in SQL:
with x as (
SELECT parse_json('{time:1621447619899}') as var
)
SELECT var:time,
var:time::number,
var:time::varchar::timestamp,
1621447619899::timestamp,
'1621447619899'::timestamp,
var:time::timestamp
FROM x;
It appears that what you want to do is execute the following:
var:time::varchar::timestamp
Reviewing the documentation it does look like the to_timestamp is looking for the number as a string, so you need to cast to varchar first, and then cast to timestamp, otherwise you get what you are getting.
The question says that Snowflake transforms it to "53351-08-15 22:04:10.000" looks right, but it doesn't look right to me.
When I try the input number in Snowflake I get this:
select '1621447619899'::timestamp;
-- 2021-05-19T18:06:59.899Z
That makes a lot more sense.
You'll need to provide more code or context for further debugging - but if you tell Snowflake to transform that number to a timestamp, you'll get the correct timestamp out.
See the rules that Snowflake uses here:
https://docs.snowflake.com/en/sql-reference/functions/to_timestamp.html#usage-notes
The ::timestamp handles strings and numeric inputs differently. I.e. a string is added to 1970-01-01 as milliseconds (correct) whereas the numeric value is added in seconds which returns a date way in the future "53351-08-18 20:38:19.000".
SELECT TO_VARCHAR(1621447619899::timestamp) AS numeric_input
,'1621447619899'::timestamp AS string_input
numeric_input = 53351-08-18 20:38:19.000
string_input = 2021-05-19 18:06:59.899
Solutions are to convert to a string or divide by 1000:
SELECT TO_TIMESTAMP(time::string)
SELECT TO_TIMESTAMP(time/1000)

Parsing Custom Date Format in MySQL

Problem
I need to query out a date value for use in some ETL processing. However, the data is stored in MySQL as a VARCHAR column in values like 1/1/19.
What I've tried
A simple CAST(myDateColumn as DATE) fails as I get values like 0001-01-19 returned back.
Question
Am I able to pass a custom date format string into the CAST call somehow to tell it how to parse out the date parts? If not, could a SUBSTRING type of function help here?
As discussed in the comments above, you can use the STR_TO_DATE() function to parse a string into a proper YYYY-MM-DD date.

Date format changes strangely

They're pretty stored in the database.
But when i take it from the node and sprinkle it into json, it changes into this format.
YY-mm-dd HH:ii:ss -> YY-mm-ddThh:ii:ss,000Z,
Why does it happen and How can i fix it?
It is getting converted to a date object and when you stringify the javascript object it will call the date.toISOString() format, take a look at this:
Node.js - How to format a date string in UTC
If you post some code we can help you.

Tableau Timestamp String to Date

i have a timestamp in my bigquery looking like this: 2017.09.25 10:22:19
i want to convert this string to a date dimension. i tried it with the dropdown menu, calculated fields like datetime, dateparse, date,... and a calculated field where i trimmed the string and took only parts of the date as a sum, but nothing is working. I always get the error that google bigquery could'nt compile my task: "Invalid date: '2017.07.03 10:52:16' "
does anyone have an idea as a solution for my problem?
regards
Date parts need to be separated with dashes, not dots, in order for the cast to work. For example,
'2017-09-25 10:22:19'
As a string, this is valid to cast both to a DATETIME and a TIMESTAMP type. If you want to convert your original string to one of these types, however, you can use PARSE_DATETIME, or similarly PARSE_TIMESTAMP:
SELECT
PARSE_DATETIME('%Y.%m.%d %T', timestamp_string) AS datetime
FROM YourTable;

Wrong MYSQL (date) output

i have a database that contains over 2000 records and the date is wrongly formatted (mm/dd/yyy). I need to change this with mysql into dd/mm/yyy.
i have this code:
UPDATE wp_team_workshop_availbility SET available_date = DATE_FORMAT('available_date', '%d-%c-%y')
but all i creates is an empty field.
If you are storing it as a date (datatype), it is just a date - there is no format. However, you also don't want available_date as a quoted string, which is trying to convert the string "available_date" into a date.
My guess is you have the date stored as a string (you really shouldn't). However, what you will want is something more like:
UPDATE wp_team_workshop_availbility
SET available_date = DATE_FORMAT(STR_TO_DATE(available_date,'%c/%d/%Y'), '%d-%c-%y');
i.e. you need to convert the string to a date and then convert it back to a string.
But really, you should take advantage of this opportunity to change your storage so you are using the right datatype.