I want to use the DATETIME_DIFF function to get th...
# gd-beginners
t
I want to use the DATETIME_DIFF function to get the first day of the month (min) until the current day to know which days have passed, could you help me please.
m
Hi Tomas, Thanks so much for reaching out! I wanted to share some helpful information about the DATETIME_DIFF function for GoodData Cloud. You can find the documentation here: https://www.gooddata.com/docs/cloud/create-metrics/maql/time-arithmetics/datetime-diff/#example-2---datetime_diff-is-applied-prior-to-aggregation-and-uses-a-time-macro For counting how many days have passed, you might find this query useful:
SELECT DATETIME_DIFF(this(MONTH),this(day),DAY)
If you’re interested in getting the specific day number, you can try this one instead:
SELECT DATETIME_DIFF(this(MONTH),this(day,1),DAY)
Also, it would be great to know if your question is related to a specific date attribute or if you’re just looking for the day number. Best regards, Mauricio Cabezas Customer Support Analyst GoodData | support@gooddata.com for you.
Hello Tomas, I would like to know if you have any further question?
t
Hi Mauricio, thanks for getting back to us. But I tested the examples I showed and also in the documentation and it didn't work. It wouldn't be of any attribute itself, it would be to get the current month and know how many days had already passed. But if we were to get it from a data attribute, what would it be like?
m
Hi Tomas, To calculate the difference between a datetime column and the current date using
DATETIME_DIFF
, you can refer to 'Example 2' in the documentation. Here’s the query you can use:
SELECT AVG(SELECT DATETIME_DIFF({label/DateA.day}, THIS(DAY)) BY {dataset/taba})
Regarding the original question, this:
SELECT DATETIME_DIFF(this(MONTH),this(day),DAY)
still is not working for you? If you need any further assistance, feel free to reach out. Have a great day!
Hello Tomas, I hope the answer provided are ok, please let me know if you need something else.