Get the date difference in "DAY" and "MINUTE" | Freemarker & Synesty Studio - freemarker

I want the date difference between to dates dipslayed in days and also minutes. The problem is that the function:
${datediff(datetime_1, datetime_2, "DAY")}
will obviously only give me the difference in days back. Putting after the "DAY" for example a && "MINUTE" will not work.
Is there a solution to this question or any workaround ?

Datediff with parameter "minute" would give you minutes and since every 1440(24hour*60minutes/hour) minute is a day you can divide by 1440 to get the day, modulo by 1440 to get remainder "minutes"

Related

Impala date subtraction timestamp and get the result in equivalent days irrespective of difference in hours or year or days or seconds

I want to subtract two date in impala. I know there is a datediff funciton in impala but if there is two timestamp value how to deal with it, like consider this situation:
select to_date('2022-01-01 15-05-53','yyyy-mm-dd HH24-mi-ss')-to_date('2022-01-01 15-04-53','yyyy-mm-dd HH24-mi-ss') from dual;
There is 1 minute difference and oracle would put the result as 0.000694444 days.
My requirement is if there is any such functionality in impala where I can subtract two timestamp value in the manner 'yyyy-mm-dd HH24-mi-ss', and get the result in equivalent days irrespective of if there is difference in days , year, hours, minute or seconds. Any difference should reflect in equivalent number of days.
Any other way where I can achieve the same thing, I am open to that as well.
Thank you in advance.
You can use unix_timestamp(timestamp) to convert both fields to unixtime (int) format. This is actually seconds from 1970-01-01 and very suitable to calculate date time differences in seconds. Once you have seconds from 1970-01-01, you can easily minus them both to know the differences.
Your sql should be like this -
select
unix_timestamp(to_timestamp('2022-01-01 15-06-53','yyyy-MM-dd HH-mm-ss')) -
unix_timestamp(to_timestamp('2022-01-01 15-05-53','yyyy-MM-dd HH-mm-ss')
) diff_in_seconds
Once youhave difference in seconds, you can easily convert them to minutes/hours/days - whatever format you want it.

Want to make the output human readable

Hello, I am trying to run some queries but my output is not right. Could anyone please help me understand what I'm doing wrong?
I am trying to find the difference between these two DATETIME values as minutes.
SELECT TO_CHAR(booking_StartTime - booking_EndTime) AS Diff FROM Booking;
Assuming that booking_StartTime and booking_EndTime are DATE fields - when doing arithmetic using DATE values in Oracle the result is a number of DAYS. Thus, to get minutes you have to multiply by the number of minutes in a day, i.e. by 24 * 60, or 1440. Also - you probably want to subtract the start time from the end time, in order to get a positive value as the result.
SELECT TO_CHAR((booking_EndTime - booking_StartTime) * 1440) AS Diff FROM Booking;
should get you what you want.

Ruby: number of times a specific day of the month (eg. 1st of each month) occurs between two dates

I'm using ruby and I've got a doubt slightly different to what I've seen answered already.
I've got two dates (today and April next year) and I'd like to count the number of times a specific day, eg. 1st of each month, occurs between both (this date could be configurable, eg, day 15th of each month, etc).
Could you guys think of a way to achieve that in Ruby?
(Date.today..Date.parse('2018/04/01')).count { |d| d.day == 15 }
#⇒ 8

combining date and time and changing it to GMT

I have read many answers for combining date and time and nothing worked so far. I am working in Oracle SQL developer version 3.1.06 and I am trying to combine date and time stamps together. Date is in format dd-mmm-yy. And time is in the following 3 formats-
1. 0348A-- meaning 3:48 am
2. 03:48:00
3. 228 -- meaning minutes from midnight, calculated as (3*60)+48.
And for all these timestamps, I want a query that gets me to this format --
mm/dd/yyyy hh:mm:ss .
I can change the dates and times to string and attach them, but then when I work in powerpivot I am not able to change them to the required format. So, I want to do it in the query itself.
I have already tried something like this-
1. CAST(deptdt as DATETIME)+CAST(time as DATETIME)
2. CAST(depdt AS TIMESTAMP(0)) + (depdt - TIME '00:00:00' HOUR TO SECOND) AS DATETIME
Please help!!

Subtracting between two dates for total days

i have three columns for Date In, Date Out, Total Days. If in Date In: 8/1/2011 and Date Out: 8/12/2011 Then the Total Days would be: 11 days. If Date Out is empty then Total Days = Current Date - Date In.
Problem: i cout get the total days if Date out is empty and using current date just fine, but getting total between date out and date in is giving me an error.
In the textbox in the reportviewer i have this expression:
=IIf(Fields!DateOut.Value=" "," ",Fields!TotalDays.Value)
The TotalDays is Current Date - Date In which i calculate in a stored procedure and just return the results.
I was thing of doing this but still i am getting an #Error in the textbox if i tried subtracting between date out and in if they are not empty.
=IIf(Fields!DateOut.Value=" ",DateDiff("d",Fields!DateOut.Value,Fields!DateIn.Value),Fields!TotalDays.Value)
Any suggestions.... Thanks
I know this is a little late, but i came up with the same issue. Here's what I did:
=CDate(Fields!DateOut.Value).Subtract(Fields!DateIn.Value).Days
Hope this helps!
Thanks for the info. Just wanted to share as I am not a programmer and this might be helpful to someone who is in my shoes that is required to write code.
I was able to create my formula from Answer 1. I had a requirement to have the Period End Date display the date 6 days prior. IE. EndDate = 06/24/2012 Field needs to display as 06/18/2012
=(CDate(Fields!EndDate.Value).AddDays(-6))

Resources