I am currently trying to figure out how to always get a leading 0 when getting current date time.
The following is the way I am currently doing it:
${date} = Get Current Date result_format=datetime
${dateyear}= Convert To String ${date.year}
${datemonth}= Convert To String ${date.month}
${dateday}= Convert To String ${date.day}
${datehour}= Convert to string ${date.hour}
${dateminute}= Convert to string ${date.minute}
The problem is that when I get date.day/minute/hour/, I get back 1-9 instead of 01-09. I am using the values to enrich a json, which expects 2 characters for each, so passing 1 results in an error, while passing 01 will work fine.
You can use zfill() function to pad strings:
${dateminute}= Set Variable 5
${dateminute}= Evaluate '${dateminute}'.zfill(2)
Related
have a list with data as float or number and I need to convert it to String for comparison with robotframework with another dataset which is in String only.
I tried string operations from robotframework but I didn't find anything to convert float to String.
There is a Builtin keyword that does just that - Convert To String, that will make any passed value to a string type.
There is not always need to make conversions.
All of these assertions below work fine:
${float}= Convert To Number 4.22
${string}= Convert To String 4.22
Should Be Equal '${float}' '${string}'
Should Be Equal As Strings ${float} ${string}
Should Be Equal As Numbers ${float} ${string}
If I run the code like so:
print(df['Col1'].to_string(index=False))
I get:
1
2
3
Now if I use the code like so (without print):
s = df['Col1'].to_string(index=False)
s
I get:
'1\n2\n3'
Where are the backslashes and 'n' strings coming from? What is the appropriate way of listing a single columns with an ultimate goal of assigning to an array?
if you want to convert a data column to a list (array), then use this code:
col_list = df['Col1'].values
or
col_list = list(df['Col1'])
The \n sequence is a popular one found in many languages that support escape sequences. It is used to indicate a new line in a string. And print function will format the given string & inserts a new line
I have a dataframe (df3) with with some values.
One of these values is the daedlines.
The data of this value is something like the following:
deadline
1419397140
1418994978
1419984000
1418702400
They are days and I want to convert the to using this:
df3$deadline <- as.POSIXct(df3$deadline, origin="1970-01-01")
Generally it was worked for me with other dataframes from other files.
However with this it gives me back this error:
Error in as.POSIXlt.character(as.character(x), ...) :
character string is not in a standard unambiguous format
How can I fix it?
It might be that you have a character or factor, and it's expecting a numeric vector for conversion from unix time :
as.POSIXct(as.numeric(as.character(df3$deadline)),origin="1970-01-01")
As a suggestion for future debugging, you can check your parameter type by using
class(df3$deadline)
and making sure you are passing the correct type to as.POSIXlt().
From the help menu for asPOSIX*():
Character input is first converted to class '"POSIXlt"' by
'strptime': numeric input is first converted to '"POSIXct"'. Any
conversion that needs to go between the two date-time classes
requires a time zone: conversion from '"POSIXlt"' to '"POSIXct"'
will validate times in the selected time zone.
I have fetched a set of dates from postgresql, they look correct:
[1] "2007-07-13" "2007-07-14" "2007-07-22" "2007-07-23" "2007-07-24"
[6] "2007-07-25" "2007-08-13" "2007-08-14" "2007-08-15" "2007-08-16"
etc.
Then I want to run a loop on them to make new sql sentences to fetch some other data sets (yes, I know what I am doing, it would not have been possible to do all the processing in the database server)
So I tried
for(date in geilodates)
mapdate(date,geilo)
Error in postgresqlExecStatement(conn, statement, ...) :
RS-DBI driver: (could not Retrieve the result : ERROR: invalid input syntax for type date: "13707"
LINE 1: ...id_date_location where not cowid is null and date='13707' or...
mapdate is a function I have written, the use of date within that is
sql=paste('select * from gps_coord where cowid=',cowid," and date='",date,"'",sep='')
So, what has happened is that R silently converted my formatted dates to their integer representations before i tried to paste the sql together.
How do I get the original textual representation of the date? I tried
for(date in geilodates){
d=as.Date(date,origin="1970-01-01")
mapdate(d,geilo)
}
Error in charToDate(x) :
character string is not in a standard unambiguous format
And I have not managed to find any other functions to create a datestring (or to "serve" the date as the string I get when listing the variable
Thanks to wush978 for pointing me in the right direction, In the end I had to do:
for(d in geilodates){
date=format(as.Date(d,origin="1970-01-01"))
mapdate(date,geilo)
}
For some reason, inside the loop the "date" variable was seen as an integer, so I explicitely had to convert it to a date and then format it...
try ?format.Date
x <- Sys.Date()
class(x)
class(format(x))
In R, the data of class Date is a numeric type.
An official way to represent Date as string is to call format.
I doubt that the format of date is defined in your case, so paste
does something unexpected.
Maybe you need to put format(x, "%Y-%m-%d") in your paste function instead of date to tell R how which format you want for Date.
I'm trying to do a query like this on a table with a DATETIME column.
SELECT * FROM table WHERE the_date =
2011-03-06T15:53:34.890-05:00
I have the following as an string input from an external source:
2011-03-06T15:53:34.890-05:00
I need to perform a query on my database table and extract the row which contains this same date. In my database it gets stored as a DATETIME and looks like the following:
2011-03-06 15:53:34.89
I can probably manipulate the outside input slightly ( like strip off the -5:00 ). But I can't figure out how to do a simple select with the datetime column.
I found the convert function, and style 123 seems to match my needs but I can't get it to work. Here is the link to reference about style 123
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm
I think that convert's slightly wrongly documented in that version of the docs.
Because this format always has century I think you only need use 23. Normally the 100 range for convert adds the century to the year format.
That format only goes down to seconds what's more.
If you want more you'll need to past together 2 x converts. That is, past a ymd part onto a convert(varchar, datetime-column, 14) and compare with your trimmed string. milliseconds comparison is likely to be a problem depending on where you got your big time string though because the Sybase binary stored form has a granularity of 300ms I think, so if your source string is from somewhere else it's not likely to compare. In other words - strip the milliseconds and compare as strings.
So maybe:
SELECT * FROM table WHERE convert(varchar,the_date,23) =
'2011-03-06T15:53:34'
But the convert on the column would prevent the use of an index, if that's a problem.
If you compare as datetimes then the convert is on the rhs - but you have to know what your milliseconds are in the_date. Then an index can be used.