Conversion of Normal Date ( YYYY-MM-DD ) to Julian Date conversion in datastage - datastage

Is there any function to convert Normal Date to Julian Date.
I have used JulianDayFromDate function in transformer but i am not getting expected output .
Sample Input :
Date -- 2013-02-02
Output Should be:
Julian Date-- 113033
( In Database we can do the query as below )
select to_date(1900000+113033,'YYYYDDD') from dual
But how to convert in Datastage ... ?

Maybe your expectations are wrong -
2456326 is the julian day for 2013-02-02 - the DataStage functions works.
Check out the Wikipedia documentation for defintions and calculations
Not sure what your 113033 is but it is not the Julian date or Julian day for the date shown.
To achieve what you want you have to do the calculation by your own.
Besides the year calcuation you could use YeardayFromDate to get the daynumer in the year.
So finally it would be something like
YearFromDate('2013-02-02') * 1000 - 1900000 + YeardayFromDate('2013-02-02')

Databases use different "day zero" values for Julian dates. Doesn't matter. The point is the ability to do date (day) arithmetic with them.
To convert back, use DateFromJulianDay() function.

Related

Tableau: Same Day Last Year Auto Filter

I am trying to compare yesterday's data to the same day the year before. For example, yesterday is 11 November 2018. I want to compare to 12 November 2017 (same day but the year before). I am wanting this to be applied automatically on the filter so all I need to do is open the file and verify the numbers are correct before sending off the report.
Any help would be appreciated.
Thanks
There are many Tableau functions that manipulate dates. A couple in particular are relevant to your problem:
Today() - returns the current date
DateAdd() - adds or subtracts an interval from a date. For instance, DateAdd('year', Today(), -1) gives the date one year prior to today. The first argument to DateAdd is the level of granularity or date part.
DateDiff() - determines the difference of the interval between two dates. DateDiff('day', [Start Date], [End Date]) returns the number of days separating the two date arguments.
The functions are well documented in the online help. Construct the formulas you need and filter accordingly.
Isolate yesterday's date as its own field. For instance if that is the max date in your data, then {max([Date])} would create an LOD of the maximum date.
Then make a calculation that will display the same date last year:
year([Date]) = year([max_date])-1
and datepart('week',[Date]) = datepart('week',[max_date])
and datepart('weekday',[Date]) = datepart('weekday',[max_date])

How to use DATE() in SSRS

I'm trying to recreate this expression from excel in SSRS:
=((TODAY()-DATE(2016,7,1))/(DATE(2021,6,30) - DATE(2016,7,1)))*100
But I'm getting an error that says date can't be used as a function in SSRS. DateValue converts it to a string and I need to calculate the percentage of time that's elapsed.
Can anyone help?
There is no Date function in SSRS - I think you actually want the DateSerial function.
The date serial function converts a year, month, and day values into a date. You might need to use DateDiff in your calculation - I don't remember if SSRS lets you subtract dates.
Use DateDiff() and CDate():
=(DateDiff("d", Now(), CDate("07.01.2016")) / DateDiff("d", CDate("30.06.2021"), CDate("07.01.2016")) *100

Converting Netezza timestamp to Julian Day Number

I have been looking for it during days but could not find how to do..
It is like:
select to_number(to_char('2015-06-24 00:00:00','J')) on Oracle.
I need to find the Julian Numeric Day value, not to be confused with the ordinal date of the year..
Conversion templates indicate that 'J' is exactly what you want.
I think the issue you have is the to_number() function, not the to_char() function. Use casts instead.
SYSTEM(ADMIN)=> select to_char('2015-06-24 00:00:00'::timestamp,'J')::int;
?COLUMN?
----------
2457198
(1 row)
You need to use the DDD (day of year) date identifier in TO_CHAR.
Reference: date and time constants.

Hive: Subtracting 1 year from current date

I'm trying to find the best way to subtract 1 year and also one month from the current date in a Hive query. Using the following, I don't believe it will take into account leap years or if the fact that months have different amounts of days so eventually the code will break. Any help would be greatly appreciated!
set my_date = from_unixtime(unix_timestamp()-365*60*60*24, 'yyyy-MM-dd');
set my_date = from_unixtime(unix_timestamp()-30*60*60*24, 'yyyy-MM-dd');
Thank!
-Rebecca
If you have date format like yyyy-MM-dd hh:mm:ss in Hive, it is easy to implement using following functions
concat((year(date_field)-1),'-', (month(date_field)-1), '-', day(date_field))
Use IF and CASE functions to implement your logic to find whether it is a leap year or not(by dividing year by 4)

Convert a Date field into Week Number in IBM DB2

I have a Date field (CHAR Datatype) which has values in this format: YYYYMMDD.
For example 20140729.
I want to convert it into a Weeknumber in format YYYYWKNO
For example, the result would be 201432.
How this can be done in IBM DB2?
Luckily for you, DB2 has some pretty good date formatting functions. Although the links for the documentation are for DB2 for Linux/Unix/Windows, it will also work on DB2 for z/OS.
You can use TIMESTAMP_FORMAT() to convert your CHAR field to an actual date, which you can then use VARCHAR_FORMAT() to format it in the way you wish:
SELECT
VARCHAR_FORMAT(
TIMESTAMP_FORMAT(
'20140801'
,'YYYYMMDD'
)
,'YYYYWW'
)
FROM SYSIBM.SYSDUMMY1
There are two different formats for "week", one is WW, which will give the week based on a week beginning with January 1 and ending January 7, and IW, which will give the ISO Week.. Please see the documentation page for VARCHAR_FORMAT for the other formats available.
The following gets week 31 instead of 32. But overall I think it is a good solution for this problem:
SELECT TO_DATE('20140801', 'YYYYMMDD') AS MYDATE
, YEAR(TO_DATE('20140801', 'YYYYMMDD')) * 100 + WEEK(TO_DATE('20140801', 'YYYYMMDD')) AS YYYYWKNO
FROM SYSIBM.SYSDUMMY1