How to adding month to date in and return in Date format in Robot Framework - selenium

I try to calculate month.
My Example code: 27/01/2020 + 20 months
Test Date
${PAYMENTDATE} Set Variable 27/01/2020
${PAYMENTDATE} Convert Date ${PAYMENTDATE} date_format=%d/%m/%Y result_format=%Y-%m-%d
${DATE} Add Time To Date ${PAYMENTDATE} 20 months result_format=%d/%m/%Y
log to console ${DATE}
But it not work, Could anyone help please?

In your code you are providing time value in months which is not valid. Unfortunately adding months to the date is not possible using the Robotframework DateTime library. From the DateTime documentation:
time: Time that is added in one of the supported time formats.
You need to provide the time value in one of the possible way e.g. You can provide days.
20 months approximates to 600 days and below code works without problem.
${DATE} Add Time To Date ${PAYMENTDATE} 600 days result_format=%d/%m/%Y
In case you are looking for exact days to be added for 20 months than you need to calculate exact number of days starting from the date you want to add 20 months to and provide it in above code instead of 600 days. You can easily find answers on how to calculate exact days using python like this here.

Related

Trying to accommodate relative defined date, such as 5 days ago, into my fixed date condition in PostgreSQL

I'm trying to condition my WHERE clause to accommodate relatively defined dates into my date filter. I'm pretty confused what type I need to use, if it's CONVERT or TO_DATE function, or if I need to put a CASE WHEN statement into my code.
This is the code that I have written so far:
WHERE event_create_verified_user_success.created_at_utc_date
BETWEEN DATE '2021-11-29' AND DATE '2021-12-05'
And this is the condition of the activity I need to finish:
If the desired date-period is not set manually using fixed dates like from “2021-11-29”
to “2021-12-05”, how would you change the where-clause to consider all data from relative
defined dates: “consider messages created between 10 days and 5 days ago (inclusive)”
I've only started PostgreSQL yesterday and the last time I've handle SQL was probably 4 years ago so I'm pretty confused at how much SQL has changed since then.
Thank you so much for helping!
The basic syntax hasn't really changed in the last 4 years (or even 15 years).
You can use current_date to obtain "today's date". You can subtract days from that
where ... between current_date - 10 and current_date - 5
If created_at_utc_date is a timestamp (= date and time) rather than a date (=date without time) it's better to use a range query though:
where created_at_utc_date >= current_date - 10
and created_at_utc_date < current_date - 4
Note the < combined with the next day you want to compare with.

Calculate date difference and return number of days

I need help to calculate the date difference and return number of days.
I used this in rtf template but it didnt work and when i hard code the dates it works!and not sure what is wrong with the data field.
UDRDAILYACTDATEDO this is variable,
UDRFCDDATEDO this is fixed date when the contract starts, and I need to calculate the cumulative days from first chargeable date FCD.
and when i try to calculate the days inside the data set in BI usining numtodsinterval it return the seconds along with the number and couldnt find a way to truncate it.

Is there a query that can add only business days , I used Date Add function but its still counting weekends?

I'm setting up web-page to display Date for scheduling. Currently I'm using Date-add to add 5 business days, using Week , but it still takes into consideration of the weekend.
I've tried the following code below and it includes weekend
select convert(varchar,dateadd(dw,5,getdate()),101)
I'm expecting it to show 5 days from today not counting the weekend.

xsl if test if the timestamp is within the past 24 hours

I would like to check if the processed date is today.
xsl:if test="ProcessedDate = 'Today'" won't work since the value of processed date is a timestamp more like 2016-06-07T09:06:54.827z
How can I mathematically convert it to check the processed date to see if it's in the past 24 hrs.
Perhaps within a ().

Battling Datediff in SQL

I am writing a little query in SQL and am butting heads with an issue that it seems like someone must have run into before. I am trying to find the number of months between two dates. I am using an expression like ...
DATEDIFF(m,{firstdate},{seconddate})
However I notice that this function is tallying the times the date crosses the monthly threshold. In example...
DATEDIFF(m,3/31/2011,4/1/2011) will yield 1
DATEDIFF(m,4/1/2011,4/30/2011) will yield 0
DATEDIFF(m,3/1/2011,4/30/2011) will yield 1
Does anyone know how to find the months between two dates more-so based upon time passed then times passed the monthly threshold?
If you want to find some notional number of months, why not find the difference in days, then divide by 30 (cast to FLOAT as required). Or 30.5-ish perhaps - depends on how you want to handle the variable month length throughout the year. But perhaps that's not a factor in your particular case.
The following statements have the same startdate and the same endate. Those dates are adjacent and differ in time by .0000001 second. The difference between the startdate and endate in each statement crosses one calendar or time boundary of its datepart. Each statement returns 1. ...
SELECT DATEDIFF(month, '2005-12-31 23:59:59.9999999'
, '2006-01-01 00:00:00.0000000'); ....
(from DATEDIFF, section datepart Boundaries ). If you are not satisfied by it, you probably need to use days as unit as proposed by martin clayton
DATEDIFF(m,{firstdate},ISNULL({seconddate},GETDATE())) - CASE
WHEN DATEPART(d,{firstdate}) >= DATEPART(d,ISNULL({seconddate},GETDATE()))
THEN 1
ELSE 0
DATEDIFF is like this by design. When evaluating a particular time measurement (like months, or days, etc.), it considers only that measurement and higher values -- ignoring smaller ones. You'll run into this behavior with any time measurement. For example, if you used DATEDIFF to calculate days, and had one date a few seconds before midnight, and another date a few seconds after midnight, you'd get a "1" day difference, even though the two dates were only a few seconds apart.
DATEDIFF is meant to give a rough answer to questions, like this:
Question: how many years old are you?
Answer: some integer. You don't say "I'm 59 years, 4 months, 17 days, 5 hours, 35 minutes and 27 seconds old". You just say "I'm 59 years old". That's DATEDIFF's approach too.
If you want an answer that's tailored to some contextual meaning (like your son who says "I'm not 8! I'm 8 and 3-quarters!, or I'm almost 9!), then you should look at the next-smallest measurement and approximate with it. So if it's months you're after, then do a DATEDIFF on days or hours instead, and try to approximate months however it seems most relevant to your situation (maybe you want answers like 1-1/2 months, or 1.2 months, etc.) using CASE / IF-THEN kinds of logic.