Get date of a candle - pine-script-v5

Im trying to get the date of the last candle, but at the moment i get only the current date.
What im looking for is this data:
Year => 2022
Month => December
Day => 24
At this moment i get this values using:
year(timenow)
month(timenow)
dayofmonth(timenow)
But what's i would like is getting this value based on last daily candle.
If i use Bareplay, using timenow, the value dont change.
Any suggestion?
Merry Christmas at all ☺️

You should use the time function :
The time function returns the UNIX time of the current bar for the specified timeframe and session or NaN if the time point is out of session.
see : https://www.tradingview.com/pine-script-reference/v5/#fun_time
time(timeframe.period) will return you the time of the actual bar, not the time now.
Then you can use year( ) , month( ) and dayofthemonth( ) to retrieve your values.

Related

How to get a specific date of next month? (Java 8)

With today's date, I should get the 16th date of next month.
For example, on passing 13-12-2021, I should get 16-01-2022.
I need to get the next month 16th day from current date (input date). Examples:
On passing 13-11-2021 should get 16-12-2021.
On passing 14-11-2021 should get 16-12-2021.
On passing 15-11-2021 should get 16-12-2021.
On passing 02-12-2021 should get 16-01-2022.
On passing 03-12-2021 should get 16-01-2022.
On passing 03-01-2022 should get 16-02-2022.
On passing 04-01-2022 should get 16-02-2022.
Any help will be much appreciated. Thanks.
java.time
One of the many strong points of java.time, the modern Java date and time API, is date arithmetic like this.
public static LocalDate nthDayOfFollowingMonth(
int desiredDayOfMonth, LocalDate currentDate) {
return YearMonth.from(currentDate)
.plusMonths(1)
.atDay(desiredDayOfMonth);
}
Try it out with your example date:
System.out.println(nthDayOfFollowingMonth(
16, LocalDate.of(2021, Month.DECEMBER, 13)));
Output:
2022-01-16
We might not have needed to convert to YearMonth and back to LocalDate. Doing so relieves both me and the reader of considering what happens if today’s day of month doesn’t exist in next month — for example if current date is 30 January (there is no 30 February). What one still wants to consider is what happens if you request a day of month tht doesn’t exist next month. For example on 13 January asking for the 30th of next month. We can try that out too:
System.out.println(nthDayOfFollowingMonth(
30, LocalDate.of(2022, Month.JANUARY, 13)));
I find the result very reasonable:
java.time.DateTimeException: Invalid date 'FEBRUARY 30'

setDate not setting date properly inside eval in batch script

--eval "var date = new Date(); date.setDate(date.getDate()-10)"'
pause
new Date() gives me the current date. I'm trying to get 10 days back date,but setDate() not setting the date correctly.I'm doing it through batch script.
I got this 1576031482772 after evaluating date.setDate(date.getDate()-10) .Please help me find a solution.
This is the expected behavior. The signature of setDate is as follows. ref
Parameters
It accepts one parameter, it should be number as a day value.
Return Value
It returns milliseconds between 1 January 1970 00:00:00 UTC and the given date
Solution
You are actually setting the day value of date. So If you want to retrieve the value, just use date.getDate(). Which will be the new date.
For more details, how it works, you can refer MDN.

Cognos date prompt for specific hours not working as expected

I'm trying to create a report with date prompt. I need a result with 11AM to 11AM data; the query I have written is;
((date(lastupdatetime) = (#prompt('Parameter1')#) and HOUR(Cast(lastupdatetime as TimeStamp))>=11)
or (date(lastupdatetime) = (#prompt('Parameter2')#) and HOUR(Cast(lastupdatetime as TimeStamp))<= 11))
But is is returning whole day data. Can anyone help me out?
The following example will return a 24 hour period starting at 11AM from a user prompted date.
[Date] between #
prompt('FromDate','date')+' 11:00:00.000-05:00'
#
and
#
_add_hours(prompt('FromDate','date')+' 11:00:00.000-05:00',24)
#

Filtering exception report for past 24 hours

Currently working with Blue Prism and I want my exception report to only bring back exceptions from the last 24 hours.
I have tried using 'Today()' in the 'Report From Dt' and 'Report To Dt' which works fine however there is a chance my process will ru into the next day and thus makes this not viable.
Is there a calculation for the past 24 hours?
The action "Get Reports Data" from BO "Work Queues" requires an input in form of DateTime variable.
The Today() function outputs a variable of the type Date, which is then cast into the datetime variable. When BluePrism casts a date to datetime, then it sets a time to a midnight. The answer for your problem is that you need to supply the action "Get Reports Data" with the DateTime variable that will be a datetime of now - 24hours!
Example solution to that could be:
Now()-MakeTimeSpan(0, 24, 0, 0)

How to get the last day of the current month in DataStage?

I have explored all the functions avialable in the trasformer, but could not found the exact function to get the last day of current month by passing date in same default format i.e. yyyy-mm-dd.Please help me in this regard.
Field("31|28|31|30|31|30|31|31|30|31|30|31", "|", MonthFromDate(InLink.dateVar))
It is more precise to establish the first day of next month then use DateFromDaysSince function to establish the day before. I created an integer(6) stage variable which contained century and month+1 from source link e.g. 201410
DateFromDaysSince(-1, StringToDate(svIHBKPR, "%yyyy%mm") : "%yyyy-%mm-%dd")
There is a transformer function called DaysInMonth.
Example: DaysInMonth(“2017-01-23”)= 31