Passing today's date in soapui with specific format - groovy

I want to pass today's date in this format 2020-12-07T20:15:15.783-06:00 by using this groovy script in soapui
${= new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )}
But I am getting the following error
Script48.groovy: 1: unexpected char: '' # line 1, column 20.
new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )```
Not sure what I am missing ? I want the date format to be matching the example.

Do it like this:
myTimestamp = new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ" )
log.info "${myTimestamp}"

Related

MOMENTJS TIME FORMATTING

I have this data :
time: "2020-12-17T13:06:13.144Z"
and then I want change this data, to be like this...
"17-12-2020 13:06:13"
but when I change with this code:
{moment(time).format("DD-MM-YYYY HH:mm:ss")}
MY OUTPUT IS NOW :
"17-12-2020 20:06:13"
MY OUTPUT EXPECTATION:
"17-12-2020 13:06:13"
How can I change this format so that it matches my expectation?
Try utc() method before format:
moment(time).utc().format("DD-MM-YYYY HH:mm:ss")
You can add custom string in moment format string with [:]
Try this
{moment(time).format("["]DD-MM-YYYY HH:mm:ss["]")}

Python format incomplete date to YYYYMM

As a start, I am extremely new at Python.
I am receiving an Excel file where the date field is incomplete. The value displays as "190808" (YYMMDD) instead of "2019-08-08".
Part of my automation attempt is to move the file to a different location, where the file is renamed. I want to use the date field to change the file name to the file description and date (e.g. "Sales figures 201908").
The code I have only works if the date format is
str(df['Bank date'][0].strftime("%Y%m"))
I have tried dateparser with the following:
dateparser.parse(df['Bank date'][0].strftime("%Y.%m"))
The error I am receiving is 'numpy.int64' object has no attribute 'strftime'
Any help will do.
Thanks.
I modified it slightly and built my own date-string using slicing.
vOldDate = str(df['Bank date'][0])
vNewDate = '20' + vOldDate[:2] + '.' + vOldDate[2:4]
Numpy is interpreting the date as an integer. To use dateparser, you need to convert that value into a string first, then parse that string, and then format the result:
dateparser.parse(str(df['Bank date'][0])).strftime("%Y.%m")
Since the input format is expected, you should specify it to ensure you get the right date:
>>> dateparser.parse(str(190808), date_formats=['%y%m%d']).strftime("%Y.%m")
'2019.08'

extracting week day in text format from timestamp in logstash

i am getting #timestamp in my logstash filter in below format
"#timestamp" => "2016-11-28T19:19:05.627Z"
i want to extract weekday and month value in text format by adding a new field for week and month . my output should be like
week-day:monday
month:nov
i am using some ruby code
ruby {
code => '
require "time"
event["week-day"] = event["#timestamp"].strftime "%a"
'
}
but getting error
Ruby exception occurred: undefined method `strftime' for "2016-11-28T19:19:05.804Z":LogStash::Timestamp {:level=>:error}
is there any way to do same in grok or in same ruby code?
any help ll be appreciated!!
You're almost there, you're just missing a little something:
ruby {
code => '
require "time"
event["week-day"] = event["#timestamp"].time.strftime "%a"
'
}

SAS not recognizing date format

I have the following character date format:
"3/1990"
"4/1990"
"5/1990"
...
I tried the following code:
data work.temps;
set indata;
newdate = input(strip(Date), MMYYSw.);
rename newdate = date;
run;
I keep on getting the following error meassage: Informat MMYYSW was not found or could not be loaded.
You may have to use a different informat to read in the character dates so that SAS can interpret them as numeric (since dates in SAS are actually numeric values), and then format them as MMYYS..
This was tested and works for me:
DATA temps;
FORMAT newdate MMYYS.;
SET indata;
newdate = INPUT(COMPRESS('01/'||date),DDMMYY10.);
RUN;
Try this with anydtdte:
data have;
input date $10.;
_date=input(compress(date,'""'),anydtdte.);
format _date MMYYs7.;
cards;
"3/1990"
"4/1990"
"5/1990"
;
run;
What you refer is a FORMAT, not INformat.
You'll use format with PUT function, for INPUT, you need informat.
Anyway I didn't find a suitable informat to be used directly, so you'll need to do more stuff:
data work.temps;
infile cards truncover;
input Date $10.;
newdate=MDY( scan(Date,1, '/'), 1, scan(Date,2, '/') );
cards;
3/1990
4/1990
5/1990
;
run;
SCAN takes Nth word from a string, MDY creates DATE from Month, Day and Year.
The code above gives the first day of the month.

Converting UTC Date to GMT in Groovy / Java

I am working with SoupUI a i need to adjust a Date/time (UTC) that i get back in a response to a GMT Date/time. The date that i get back in the respone looks as followes:
2012-11-09T00:00:00+01:00
I would like to convert this to
2012-11-08T23:00:00Z
Unfortunatly i lack Java skils and therefore also Groovy skils to be able to do this on my own. i did a lot o searches on date convertions but until now i was still unable to find what i was looking for. i will keep searching. if i do manage to get the solution then i will post it here.
Assuming there isn't a colon in the timezone portion, I believe this should work:
// Your input String (with no colons in the timezone portion)
String original = '2012-11-09T00:00:00+0100'
// The format to read this input String
def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" )
// The format we want to output
def outFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'" )
// Set the timezone for the output
outFormat.timeZone = java.util.TimeZone.getTimeZone( 'GMT' )
// Then parse the original String, and format the resultant
// Date back into a new String
String result = outFormat.format( inFormat.parse( original ) )
// Check it's what we wanted
assert result == '2012-11-08T23:00:00Z'
If there is a colon in the TimeZone, you'll need Java 7 for this task (or maybe a date handling framework like JodaTime), and you can change the first two lines to:
// Your input String
String original = '2012-11-09T00:00:00+01:00'
// The format to read this input String (using the X
// placeholder for ISO time difference)
def inFormat = new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssX" )

Resources