Hi
is it possible to have a block that offset a date by hours/days/months/years ?
Hello @mohammad_altoiher!
Could you please give me an example of how you are going to use this block, because I’m not entirely sure what you mean?
Regards,
Alexander
Hey @Alexander_Pavelko
well i want to build a query to get the users that don’t have any activity in the past x days.
i already have a date column in the table.
Hey @Viktor_Mudrevsky
That’s in seconds… its why i asked for hours and days and months. its make no sense to convert a month into seconds. don’t you think so? so a month is 2,419,200 second
Hello, @mohammad_altoiher.
You can add values to the current date in any unit of time, and then simply convert it to a timestamp.
Best Regards, Nikita.
so you mean i don’t use the offset date block? if you mean the offset date block. then the block will be like this in previous month offset
Can this block help you?
And also:
its why i asked for hours and days and months.
Is a month 31, 30 or 28 days? We use seconds because it’s more reliable.
how can make that block work with a where clause? and how can i select the current date minus month with that block?
here is an idea
would it be possible to manipulate the date directly? like directly access the days portion of the date and change them? like this:
01/01/2022
30/01/2022
I still don’t understand why seconds don’t suit you?
because it look ugly to do it like that
imagine the number of seconds if i want a year difference?
Let’s split your issue into small pieces
how to use it in a
whereClause
?
the same way as you use numbers/strings/etc
would it be possible to manipulate the date directly? like directly access the days portion of the date and change them?
the question is not clear to me, Date
instance has a different presentation for different locale, for instance for
- for you, this will be 30/01/2022
- for me, it will be 01/30/2022
- for another one, it could be
2022. 01. 30.
- see Date.prototype.toLocaleDateString() - JavaScript | MDN
so as you can see there is no single format for date
However, if you use a timestamp it will be the same for any zone/locale, therefore we recommend you to use timestamp in a where clause
That’s in seconds… its why i asked for hours and days and months. its make no sense to convert a month into seconds. don’t you think so? so a month is 2,419,200 second
Help me to understand your motivation for adding such blocks as Month/Day/Week
when there is already a clear mechanism for using seconds. Instead of the magic number 2,419,200
, you can use the calculation 30 * 24 * 3600
, in my opinion, this is more clear. Or you can create a variable a put there a day in seconds and then use it in your expression. Does it make sense?
is it possible to have a block that offset a date by hours/days/months/years ?
with hours/days
it is possible to add shortcuts An hour in Seconds
and A Day in seconds
, but with the month it’s not clear what value should be there 30 days in seconds
or 31 days in seconds
or 28 days in seconds
, so such block won’t be intuitive and it will lead to new issues from other customers, the same with year
, what do you think about that?
@vladimir-upirov
Thank you for this great explanation. you make a valid points on the month not constant value.
from my understanding the system deal with timestamps only to calculate the date.
will it be a valid solution to convert the timestamp to a date string then make the change to the string then convert the string to a timestamp again?
with this solution months and years calculations will be constant regardless of the month length in days and seconds.
if you think this solution doesn’t work i will use your method of calculation the seconds
from my understanding the system deal with timestamps only to calculate the date.
yes, into the local time zone (where the server is running). It means when you request records with timestamp you can be sure the server will return it to you, but when you request with 30/01/2022
there could be no records because for the server the date is 29/01/2022
(depends of the time)
will it be a valid solution to convert the timestamp to a date string then make the change to the string then convert the string to a timestamp again?
yes, this is a valid case
I’ve created a ticket BKNDLSS-29162 to discuss adding:
- create a new block
An Hour in seconds
- create a new block
A Day in seconds
Hello @mohammad_altoiher
We have added a new codeless block that will be useful to you.
Regards,
Inna