Hive from_unixtime behaving differently for different dates - datetime

I am trying to get week number for a given date. But its working for few dates and not working for couple of dates.
Followed this link https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
select from_unixtime(unix_timestamp('2015-12-31','yyyy-MM-dd'),'w') week_in_year;
The above code is returning 1
select from_unixtime(unix_timestamp('2016-12-31','yyyy-MM-dd'),'w') week_in_year;
The above code is returning 53. I think the first code snippet also should give something like 53/52. Any help is appreciated in solving.

Related

Extraction of year only instead of date in python

Please can someone help with code to extract only the year and set it as a new column in data using python from the above photo attached here. when I try, the result shows no consistency, it gives me different values. it extract both the year and date instead of only the year. I think the year is the second character. I used different code and it isn't working.
I tried using this codes below
df_movies['correct_year'] = df_movies['released'].astype(str).str[-20:]
df_movies['years_scorrect'] = df_movies['released'].astype(str).str[:12]

Pulling bond security names from ISIN in R

I'm trying to convert individual ISINs into their respective bond names in R. I've been able to achieve it in Excel, but weirdly passing the 'bdp' function doesn't seem to work in the desired way in R.
To give an example, I currently have an ISIN for a government bond: GB00BK5CVX03, I would like to dynamically convert said ISIN into the name for this bond (UKT 0.625 06/07/2025 GOVT).
In excel, I do:
=BDP("GB00BK5CVX03 ISIN", "ID_BB_SEC_NUM_DES")
And it delivers a useable result: UKT 0.625 06/07/25
In R, I try pretty much the same thing:
bdp("GB00BK5CVX03 ISIN", "ID_BB_SEC_NUM_DES")
And it delivers:
I was expecting a similar result to the excel output (namely a string that I could then attach to an object).
Does anyone know where I'm going wrong? Any help is much appreciated.
So I managed to solve it, turns out the API will not respond to "ISIN" being at the end of the ISIN, even though it works fine in excel.
Therefore changing the code to read:
bdp("GB00BK5CVX03 GOVT", "ID_BB_SEC_NUM_DES")
Solved the issue.

Quantmod R , how to select cells with Sys.date?

I'm making some calculations based on quantmod for some stocks.
Below I prepared a very simple example to reflect what I'd like to do which is at this time select some cells based on date, for example yesterday.
library(quantmod)
getSymbols("BAC", from="2018-06-18", src="yahoo")
As a result I get the following:
Now I'd like to make some calculations with the volume of yesterday so I wonder if something like this could work:
# I would like to multiply yesterday's volume for 1.05.
Vol_k <- (BAC$BAC.Volume Sys.Date()-1) * 1.05
How do I use sys.date here to indicate today -1 and select the volume cell of yesterday date?
Thank you very much for any comment.
V.
When I pulled this data, I don't get anything for yesterday being the 4th July (timezone I assume, or maybe due to public holiday in US?) so I did it for 2 days ago.
BAC[Sys.Date() - 2, "BAC.Volume"]
should give you the desired result of the volume. Did a bit of research (https://s3.amazonaws.com/assets.datacamp.com/blog_assets/xts_Cheat_Sheet_R.pdf)
last(BAC, '1 day')$BAC.Volume
should give you the last day, regardless of weekends/ holidays
You can always get the last value by accessing the index.i.e.
xts.object[max(index(xts.object),column]
In your case:
BAC[max(index(BAC)),"BAC.Volume"]

OSB Xquery :Date calculation

All,
I want to do a date subtract operation in Xquery, OSB 12C.Basically, have to check if an input date is < 6 months from the system date.
i.e- how to do in xquery : (SystemDate - inputDate) < 6 months
Have went through:
https://docs.oracle.com/cd/E13214_01/wli/docs92/xref/xqdtopref.html but not able to compile any of the function listed there. Have also added the namespace in xquery. Do I need to add any library.
Any pointer is highly appreciated.
OSB has some extensions for dates, which you can read about here.
But, you might not even need that for simple stuff like you mentioned.
All,
Issue got resolved.Please find the link for the logic:http://developer.marklogic.com/pipermail/general/2015-February/016462.html
Subtracting dates give you dayTimeDuration in XQuery.
Following code is a simple and accurate way to check time intervals.
days-from-duration(fn:current-date() - $inputDate) < 180
180 is number of days you need to validate.

Date Filter in SSRS 2008

I am working with SSRS 2008. I have a table in my report consisting a date/Time Column (DOB). I have a date/time parameter (MyDate) as well. I am trying to set a Filter on my data set like
FormatDateTime(Fields!DOB.Value,2)<=FormatDateTime(Parameters!MyDate.Value,2)
It doesn't filter my table correctly. But if I remove FormatDateTime function then it works fine. i want to understand whats the problem here.
FormatDateTime will return a string, so you're not comparing dates anymore but rather their string representations.
Comparing the dates 02-Feb-2012 and 10-Oct-2012 will give different results than comparing the strings 2/2/2012 and 10/10/2012.
As mentioned in the comment, it looks like you're just trying to remove the time portion from dates?
Something like this should work, i.e. converting the strings back to dates.
CDate(FormatDateTime(Fields!DOB.Value,2)) <= CDate(FormatDateTime(Parameters!MyDate.Value,2))
But this is just one suggestion, there are any number of ways of doing this.

Resources