How to subtract a date from another date using Robot Framework? - datetime

i'm using Robot Framework Keyword Subtract Date From Date to test that a date is between 2 dates(For example 11/06/2020 is between 07/06/2020 and 20/06/2020), but i'm getting an error in my log file ValueError: Invalid timestamp. The date is a String extracted from a Span Text and i convert it to date This is my code :
${date}= Get Current Date result_format=datetime
${postdate}= Get Text xpath://app-post[1]//div[1]//div[1]//div[1]//div[2]//div[1]//div[2]//div[1]//div[2]//span[2]
${postdate}= Convert Date ${postdate} date_format=%d/%m/%y
${date}= Convert Date ${date} result_format=%d/%m/%y
${temp} = Subtract Date From Date ${postdate} ${date}
Should Be True ${temp}>=0

The problem is you don't follow the allowed format for the keyword Subtract Date From Date mentioned here: https://robotframework.org/robotframework/latest/libraries/DateTime.html#Date%20formats
%y will give you 20, but that obviously is not enough. If I change it to %Y, it will give me 2020 for the current year, and the keyword Subtract Date From Date doesn't complain anymore about invalid timestamp. You'd also need to change it to something like date_format=%Y/%m/%d, that is to change the order of %Y, %m, and %d.
EDIT:
I can now see you're also using date_format as well as result_format with Convert Date. That's another bug in your code, you need to use result_format with both.
EDIT 2:
The full working example:
(And you're not using BuiltIn library here, these datetime keywords are from DateTime library)

The below script worked (Used the static PAST_DATE to check the sample run ):
${date}= Set Variable 21
${month}= Set Variable 12
${year}= Set Variable 2019
${PAST_DATE}= BuiltIn.Catenate SEPARATOR=/ ${year} ${month} ${date}
Log ${PAST_DATE}
${CURRENT_DATE}= Get Current Date result_format=%Y/%m/%d
Log ${CURRENT_DATE}
${DIFFERNCE_IN_DAYS}= Subtract Date from Date ${CURRENT_DATE} ${PAST_DATE} verbose
Log ${DIFFERNCE_IN_DAYS}
#{total_days}= Split String ${DIFFERNCE_IN_DAYS}
${final_days}= Set Variable ${total_days[0]}
Log ${final_days}
Should be true ${final_days} >= 0

Related

robotoframework selenium calculate yesterday date in python script

I have
${date}= Get Current Date result_format=%Y-%m-%d
but I need yesterday date... how can I calculate -1day? I try format %d-1 but not work
The DateTime library has an Add Time To Date keyword which should do what you need:
${CurrentDate}= Get Current Date result_format=%Y-%m-%d
${newdatetime} = Add Time To Date ${CurrentDate} -1 days

How to change UK date format in LogicApp

Im trying to convert a U.K. input date (dd-MM-yyyy) to format (yyyy-MM-dd)
I tried
"#formatDateTime('15-03-2019','yyyy-MM-dd')" ==> Error
but got error:
'In function 'convertTimeZone', the value provided
for date time string '15-03-2019' was not valid. The datetime
string must match ISO 8601 format.'
How do I go about converting this input date? The input format is (dd-MM-yyyy) and cannot be changed.
I can easily convert from (MM-dd-yyyy) as shown below, but im not able to convert from (dd-MM-yyyy)
"#formatDateTime('03-15-2019','yyyy-MM-dd')" ==> OK
Date and time functions provided by azure logic app cannot recognize the timestamp in dd-MM-yyyy format.
After my research, there is no existing function that can directly solve this problem, but you can use substring and concat to deal with this problem.
The workflow of the logic app looks like this:
The expression of the formatDataTime:
formatDateTime(concat(substring(<your-date-string>,6,4),'-',substring(<your-date-string>,3,2),'-',substring(<your-date-string>,0,2)),'yyyy-MM-dd')

Nifi - how to add days to the date

Could somebody tell me how I can add x number of days to a date attribute that is in the format ("yyyy-MM-dd") in Nifi.
Use toDate function to convert into unixtime then use plus function with milliseconds and finally use format function to get your desired format
Adding 1 day:
${date:toDate("yyyy-MM-dd"):toNumber():plus(86400000):format("yyyy-MM-dd")}
Example:
i'm having date attribute to the flowfile with value as 2018-01-10 and want's to add 1 day to the date attribute value.
Milliseconds for 1 day(24hr) is 86400000 so in the below expression i'm adding one day to the date attribute value.
Add new attribute in update attribute processor as
add_day
and value as
${date:toDate("yyyy-MM-dd"):toNumber():plus(86400000):format("yyyy-MM-dd")}

Can't format the date using moment.js

Can't format the below date using moment.js, the below statement returns Invalid Date
moment('20171206T062406927Z').format('D-MMM-YYYY');
Please help me on this.
You need to tell moment which format your date string is in:
moment('20171206T062406927Z', 'YYYYMMDD[T]HHmmssSSSZ', true).format('D-MMM-YYYY');
Edit: updated as per #VincenzoC comment to ensure the timestamp is parsed in UTC
Also fix: use HH for 24-hour format (not hh), and pass a third true parameter to ensure the timestamp is parsed in strict mode.

Reporting Services Expression for Week of Year

I have a Report that I send a parameter to as 'WeekStart'. This is based on a selection a user makes on a datepicker.
I'm using the following to extract the week of the year:
=DatePart("ww", Parameters!WeekStart.Value)
The problem I'm having is that when I pick the day 03/01/2012 (dd/MM/yyyy format), the week of the year is returned as 9, which would technically be true had the date been 03/01/2012 with a dateformat of MM/dd/yyyy.
I've tried using CDate, FormatDateString etc but nothing seems to be working. I either get #Error or it returns as the 9th week of the year.
Any suggestions?
What you can do is this:
use YourDatabase
go
set dateformat dmy
go
That will set the date format for your database, and that should get your DATEPART function working as expected.
SET DATEFORMAT (MSDN)

Resources