Robotframework - Day of the month without zero-padded decimal number - robotframework

I use this:
${today}= Get Time
${today_formated}= Convert Date ${today} result_format=%d
The result is 01 for the 1st day of the month but I need 1.
%d is Day of the month as a zero-padded decimal number. 01, 02, …, 31
How to remove 0 at the start?
My question is on the day of the month not on the month number
full robotframework script:
*** Settings ***
Library SeleniumLibrary
Library DateTime
*** Keywords ***
test
${today}= Get Time
${today_formated}= Convert Date ${today} result_format=%d
Log To Console ${today_formated}
*** Test Cases ***
PLFT
[Tags] foo|AC0
Given test
01

Use Replace String Using Regexp from standard library String
${today}= Get Time
${today_formated}= Convert Date ${today} result_format=%d
${today_no_padding}= Replace String Using Regexp ${today_formated} ^0 ${EMPTY}
This transforms values with leading zeros like 01 to 1 but values just containing zeros like 10 would remain the same.
To use the library, add a declaration to your settings:
*** Settings ***
Library SeleniumLibrary
Library DateTime
Library String

Related

Comparing two date values in RobotFramework

I'm trying to compare two date values using conditional statement. My plan is to validate DueDate against CompletionDate and determine if the value of CompletionDate is greater than DueDate which is not valid date value. Tried different resolution but didn't work for my desired result.
Test Date
${a} Convert Date 12/30/2023 result_format=%Y/%m/%d date_format=%m/%d/%Y
${b} Convert Date 12/16/2022 result_format=%Y/%m/%d date_format=%m/%d/%Y
IF ${a} > ${b}
Log To Console A:${a} is greater than B:${b}
ELSE
Log To Console B:${b} is greater than A:${a}
END
The result is ${b}
My conclusion here is that the IF condition here is treating the date values differently
Is there any way to do this, I have browse already in the RobotFramework documentation but nothing fits to my problem. Thank you!
I think RF tries to do arithmetic on your dates. You can test this by trying date `1/1/2022'. There are two workarounds:
Put quotes around variables: IF '${a}' > '${b}'
Convert dates to epoch: result_format=epoch
Here is a code sample:
*** Settings ***
Library DateTime
*** Variables ***
${a_date} 12/30/2023
${b_date} 12/16/2022
*** Test Cases ***
Test Date with Epoch
${a_epoch} Convert Date ${a_date} result_format=epoch date_format=%m/%d/%Y
${b_epoch} Convert Date ${b_date} result_format=epoch date_format=%m/%d/%Y
IF ${a_epoch} > ${b_epoch}
Log To Console \nA:${a_epoch} is greater than B:${b_epoch}
ELSE
Log To Console \nB:${b_epoch} is greater than A:${b_epoch}
Fail A should be greater than B
END
Test Date with String
${a_str} Convert Date ${a_date} result_format=%Y/%m/%d date_format=%m/%d/%Y
${b_str} Convert Date ${b_date} result_format=%Y/%m/%d date_format=%m/%d/%Y
IF '${a_str}' > '${b_str}'
Log To Console \nA:${a_str} is greater than B:${b_str}
ELSE
Log To Console \nB:${b_str} is greater than A:${b_str}
Fail A should be greater than B
END

Is there a Stata function to delete the date in a DateTime variable?

I have a date-time variable called assign1_submission (type double and format %tchh:MM:SS_AM). I have another date-time variable time_due (type double and format %tchh:MM:SS_AM).
gen double time_due = clock("12:00 PM", "hm")
format time_due %tchh:MM:SS_AM
In the assign1_submission that I imported from MS Excel, the variable only contained a time. However, in the data browser, Stata attached a date to the entry.
Despite only telling Stata a time, my time_due variable has a date in the entry.
What I want to do is delete the date in both variables, because I want to see the time difference between time_due and assign1_submission.
So, I tried the following code:
replace assign1_submission = hh(assign1_submission)
replace time_due = hh(time_due)
gen time_difference = time_due - assign1_submission
According to Stata:
hh(e_tc)
Description: the hour corresponding to datetime e_tc (ms. since
01jan1960 00:00:00.000)
When running this code:
replace assign1_submission = hh(assign1_submission)
Stata disregards the previous time: everything is overwritten to state: 12:00 AM, where a date is still attached to the entry.
Can someone please help to delete the date in both the assign1_submission and time_due variables so that I can determine the difference in hours between the two variables?
Date-times in Stata are counted in milliseconds (ms) since the start of 1960. You can discard the date element by getting the remainder on division by 24 * 60 * 60000, the number of ms in 1 day.
The time concerned is still tacitly a time on 1 January 1960.
clear
set obs 1
gen double datetime = clock("4 July 2020 18:00:00", "DMY hms")
format datetime %tc
gen double time = mod(datetime, 24 * 60 * 60 * 1000)
format time %tcHH:MM:SS
l, noobs
+-------------------------------+
| datetime time |
|-------------------------------|
| 04jul2020 18:00:00 18:00:00 |
+-------------------------------+
Otherwise it's hard to follow your assertions. Stata doesn't change data because you look in the browser. What you are showing as daily dates pertains to different variables.

controlM variable for YYYYMM?

I'm using ControlM and in a command, I would like to find a variable that gives me the date in this format : YYYYMM
I found there is %%$DATE variable but it gives YYYYMMDD
Thanks for you help
It is possible to define and concatenate a variable that will represent the date in such a format.
These are available:
Day DD, %%DAY,
Month MM, %%MONTH,
Year YY, %%YEAR,
Year YYYY, %%$YEAR
Prefer %%$OYEAR AND %%OMONTH over %%$YEAR and %%MONTH
I suggest using the variables %%$OYEAR and %%OMONTH over %%$YEAR and %%MONTH. The reason is that date variables beginning with O refer to processing dates and do not necessarily coincide with the system date. For this case you could use any of the following options:
1. YYYYMM = %%$OYEAR.%%OMONTH
2. YYYYMM = %%SUBSTRING %%$ODATE 1 6
The $ symbol preceding the variable %%$OYEAR or %%$ODATE indicates that the year is returned in 4-digit format, instead of OYEAR or ODATE which print the year with only 2 digits.
The dot (.) character is used for concatenate variables.
For example: For the order day May 29, 2020.
1. %%$ODATE would print 20200529
2. %%ODATE would print 200529

How to convert chararray to datetime with milliseconds in pig latin

I wish to convert following value which is a chararray in pig
2016-05-11 23:59:57.628197
to
2016-05-11T23:59:57.628-05:00
How can I do it ?
Following is what I tried considering alias 'a2' contains list of datetime values in chararray in the column named 'input_date_value'
FOREACH a2 GENERATE input_date_value AS input_date:chararray,
ToDate(input_date_value,'YYYY-MM-DD HH:mm:ss.SSSSSS') AS modification_datetime:datetime;
For input -
2002-07-11 16:58:40.249764
Output is -
2002-01-11T16:58:40.249-05:00
The month values like '07' are not getting picked up,
The created timestamp has month set to 01' i.e. January everytime for all dates.
Can someone help. What am I doing wrong ?
https://pig.apache.org/docs/r0.11.1/func.html#to-date ToDate takes SimpleDateFormat only supports milliseconds http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
The -05:00 you see is the time zone ToDate is actually truncating to 3 digits as it supports only milliseconds
Use lowercase character d instead of uppercase D for parsing date values.
Now, I have managed to fix it myself on (In Pig 0.11)
Apparently Pig 0.11 does not support the date format components I used earlier for parsing the month and date.
I found below inference which hints on the incompatibility as mentioned https://www.w3.org/TR/NOTE-datetime
Use:
'YYYY-MM-dd HH:mm:ss.SSSSSS'
instead of 'YYYY-MM-DD HH:mm:ss.SSSSSS'
It now gives correct output.
Input:
2001-11-28 16:04:49.22388
Output:
2001-11-28T16:04:49.223-05:00

Change database value based on date (ASP)

I have 3 dropdown lists in a form for the user to input the date by day, month and year. How can I make that once t is the date that been input by the user, it will change the status from PUBLISH to UNPUBLISHED in the database?
Below is my codes:
Need your help. Thanks.
Why don't you use the DateSerial function to convert the separate values into date values, and use that to compare two dates.
From the page at W3Schools:
The DateSerial function returns a Variant of subtype Date for a specified year, month, and day.
Syntax
DateSerial(year,month,day)
Parameter Description
year Required. A number between 100 and 9999, or a numeric expression. Values between 0 and 99 are interpreted as the years 1900–1999. For all other year arguments, use a complete four-digit year
month Required. Any numeric expression
day Required. Any numeric expression
Examples
Example 1
document.write(DateSerial(2010,2,3))
The output of the code above will be:
2/3/2010
Example 2
Subtract 10 days:
document.write(DateSerial(2010,2,3-10))
The output of the code above will be:
1/24/2010

Resources