Datastage.. I have a field which has the value say 59.0900..I want to convert it to 05909 - datastage

I have a field which has the value say 59.0900..I want to convert it to 05909
Can somebody help me with that..Im working on datastage IBM infosphere

Convert the field into String
Trim the trailing zeros and decimal point
convert back to Decimal or integer

Related

How to Format a String with Leading Zeroes to Decimal in TSQL?

I'm trying to parse a string such that the amount field is formatted with 2 decimal places. The original data provides 2 decimal place accuracy. However, the amount field in the data file is 16 characters long with leading zeroes. For example:
0000000000407981
should convert to 4079.81.
I've tried the following in my select statement:
format((substring([Column 0],51,16)/100), '.00') as CheckAmount,
This produces an amount with 2 decimal places but rounds to the nearest whole dollar. I'm using SQL Server 2016.
How do I modify my statement to ensure the CheckAmount is formatted with 2 decimal point accuracy and contains an accurate value?
Update: I attempted to convert to integer as follows:
format(convert(int, (substring([Column 0],51,16)/100.0)), '.00') as CheckAmount,
Unfortunately, I receive an error stating:
Arithmetic overflow error converting varchar to data type numeric.
How should I remedy this?
The divide by 100 does an integer division. You do not get decimal numbers. Dividing by 100.0 will.
declare #num nvarchar(20) = '0000000000407981';
select convert(bigint, #num)/100.0;
Fiddle
I was able to solve this issue with the following code snippet:
CAST((CAST(substring([Column 0],51,16) as int)/100.0) as decimal(18,2)) as CheckAmount,
Hope this helps anyone who might need to accomplish a similar task.

In snowflake , how to convert one date format to another format. From YYYYMMDD to YYYY-MON-DD

I have table ABC in which I have column Z of datatype Date. The format of the data is YYYYMMDD. Now I am looking to convert the above format to YYYY-MON-DD format. Can someone help?
You can use to_char
TO_CHAR(Z,'YYYY-MON-DD')
Depending on what the purpose of the reformatting is, you can either explicitly cast it to a VARCHAR/CHAR and define the format, or you can change your display format to however you'd like to see all dates:
ALTER SESSION SET DATE_OUTPUT_FORMAT = 'YYYY-MON-DD';
It's important to understand that if the data is in a DATE field, then it is stored as a date, and the format of the date is dependent on your viewing preferences, not how it is stored.
Since the value of the date field is stored as a number, you have to convert it to date.
ALTER SESSION SET DATE_OUTPUT_FORMAT = 'YYYY-MON-DD';
select to_date(to_char( z ), 'YYYYMMDD');
(adding this answer to summarize and resolve the question - since the clues and answers are scattered through comments)
The question stated that column Z is of type DATE, but it really seems to be a NUMBER.
Then before parsing a number like 20201017 to a date, first you need to transform it to a STRING.
Once the original number is parsed to a date, it can be represented as a new string formatted as desired.
WITH data AS (
SELECT 20201017 AS z
)
SELECT TO_CHAR(TO_DATE(TO_CHAR(z), 'YYYYMMDD'), 'YYYY-MON-DD')
FROM data;
# 2020-Oct-17

How to convert a time string to integer in Tableau

I have time data that is currently a string in the format of hours:minutes:seconds. For example, I want to be able to convert the string 00:03:30 to 210 seconds. I'd like this to be created in a calculated field for total seconds, thanks.
Utilizing the DATEPARSE function, you can use the following expression:
datediff("second", dateparse("HH:mm:ss", "00:00:00"), dateparse("HH:mm:ss", "00:03:30"))
Replace "00:03:30" with your field.

Converting long (numbers) text datatype (with blank values) to date

I have troubles converting HubSpot UNIX timestamp to date. Timestamp is stored as text value.
Value looks like this:
1549324800000
My logic was first to convert the number to bigint and later converted it to date using:
TO_CHAR(TO_TIMESTAMP(properties__vape_station__value)), 'DD/MM/YYYY')
What would be the best way to achieve converting UNIX Timestamp in text type to date in PostgreSQL 11.
You can cast the value in that column to a bigint and then use to_timestamp.
But apparently that column also stores empty strings rather than NULL values if no value is present, so you need to take that into account:
to_timestamp(nullif(trim(properties__vape_station__value),'')::bigint/1000)
This would still fail however if anything else than a number is stored in that column.

Date format in SSRS Expression

I am trying to change the date format for one of my field to dd/MM/yyyy but every time I used the below expression I get dd/MM/yyyy as the value in the cell instead of changing the format.
The data source that I am using is Teradata.
Expression used: =Format(FormatDateTime(Fields!DATE.Value, DateFormat.ShortDate),"dd/MM/yyyy")
Can some one help me with where am I going wrong.
Any help would be appreciated.
The FormatDateTime function returns a string instead of a date. When the FORMAT function tries to format it, it doesn't find a date field so it returns the characters in the format.
If your field is a date, you should be able to format the field without conversion:
=Format(Fields!DATE.Value,"dd/MM/yyyy")
If it does need to be converted first, try using the CDATE function:
=Format(CDATE(Fields!DATE.Value),"dd/MM/yyyy")