Codeless date offset by days

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.

Hi @mohammad_altoiher

You can use this block

Regards,
Viktor

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?
image

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 :slightly_smiling_face:
imagine the number of seconds if i want a year difference?

Hi @mohammad_altoiher

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

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

1 Like

I’ve created a ticket BKNDLSS-29162 to discuss adding:

  1. create a new block An Hour in seconds
  2. create a new block A Day in seconds
1 Like

Hello @mohammad_altoiher

We have added a new codeless block that will be useful to you.

Regards,
Inna

1 Like