Show current date in Coupa/Liquid - liquid-layout

I am trying to show the current date in Coupa.
I used this code:
{% assign today = "now" | date: "%s" %}
But it only displays now string as output.

Will this be for purchase order templates? If so, I think you will want to use:
{{ purchase_order.created_date | date: "%Y/%m/%d" }}

Related

Get the value of count in bash Linux

I have below string like below
<html>
<body>
<h1>|| name: xzy || class: 9 || date: 07-01-2022 || marks:25</h1>
</body>
</html>
I want to retrieve only marks I.e 25 . All the string values keeps changing. The name , date and marks are constant . I just want to get only marks value I.e 25
Please help
sed -nE '/marks:[[:digit:]]+/s/^.*marks:([[:digit:]]+).*$/\1/p' path/to/file.html

ArgumentError while parsing date string in Ruby

I'm trying to determine the amount of days from the last .rpm that was installed using ruby, however when I try to format using the Date class, I'm getting that it's an invalid date (ArguementError) on line 5. I've tried methods of converting it to an integer as well but nothing seems to work. Any thoughts?
require 'date'
require 'time'
tset = `rpm -qa --last | head -1 | rev | cut -d ' ' -f4-6 | rev`
atime = Date.strptime(tset, '%Y-%m-%d')
today = Date.today
btime = Date.strptime(today, '%Y-%m-%d')
daterange = ("btime - atime")
puts daterange
Here is the output of my rpm command
[root#default-centos-67 dev]# rpm -qa --last | head -1 | rev | cut -d ' ' -f4-6 | rev
18 Nov 2016
Your call to strptime isn't using the correct format for the date string you are parsing.
The correct date string is: %d %b %Y
%d is the two digit (zero padded) day of the month
%b is the abbreviated month name
%Y is the 4 digit year
Note that these are space-delimited, not hyphen delimited.
All together, here's how to parse the date from tset:
Date.strptime(tset, '%d %b %Y')
The result of your rpm command is "18 Nov 2016" and your Date.strptime command is looking for a date with a different format.
Change:
atime = Date.strptime(tset, '%Y-%m-%d')
to
atime = Date.strptime(tset, '%d %b %Y')
I almost always turn to the documentation on strftime to help me with flags for parsing Date and DateTime objects.

how to convert given date to customized date in shell scripting

I am completely new to shell scripting.
I need to change the format of given date to customized format like i have date in a variable with format as MM/DD/YY HH:MM:SS but i want date in a format as MM/DD/YYY HH:MM:SS which is having four digits of the year.
We can change the sys date format but i need the same in a variable.
My code as below
START_DATE="12/20/14 05:59:01"
yr=`echo $START_DATE | cut -d ' ' -f1 | cut -d '/' -f3`
yr_len=`echo $yr | wc -c`
if [ $yr_len -lt 4 ]
then
tmp_yr="20${yr}";
else
1=1;
fi
ln=`echo $tmp_yr|wc -c`
After this i strucked in reframe the same date in wanted format.
Can some one please help me
Regards,
Sai.
Using GNU date:
date -d'02/16/15 09:16:04' "+%m/%d/%Y %T"
produces
02/16/2015 09:16:04
which is what you want. See man date for details about the formatting, or this question for a number of great examples.
One option may be using the date/time functions inside awk. Here is a oneliner:
echo '02/16/15 09:16:04' | sed 's\[/:]\ \g' | awk '{d0=$3+2000FS$1FS$2FS$4FS$5FS$6; d1=mktime(d0);print strftime("%m/%d/%Y %T", d1) }'
output is:
02/16/2015 09:16:04
You can find more strftime formats in https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html

Playing with dates in bash: passing variables

I'm trying to make some calculations with date in bash script but can't find out the right syntax. I get a string from a file that I convert to a date. Then I want to get the date for one and two days ahead. Looking on another StackOverflow posts it looked easy adding days to today date. This is what I am doing now:
# Extract date string from file
ctldate=`awk 'NR==8 { print $4 }' a-AC-2015-02-10-120000-g3.ctl`
echo $ctldate
12:00Z10feb2015
# Convert string to date
ctldate2=`date +'%d/%m/%Y' -d $ctldate`
echo $ctldate2
10/02/2015
# Try to add a day, should be 11/02
data1=$(date +'%d/%m/%Y' -d "$ctldate" --date='1 day')
echo $data1
12/02/2015
# Also tried
data1=$(date +'%d/%m/%Y' -d "$ctldate2" --date='1 day')
echo $data1
12/02/2015
# And
data1=`date +'%d/%m/%Y' -d $ctldate --date='1 day'`
echo $data1
12/02/2015
It seems that I'm not properly passing $ctldate var to command and that the base date for calculation is today.
Thanks in advance
When you pass several -d or --date, date uses the last one. So when you do:
date -d "$ctldate" --date='1 day'
date will take into account --date='1 day' as it's the last -d/--date argument, and will happily show you tomorrow's date.
Instead you should use:
date -d "$ctldate +1 day"

Change datetime to timestamp in bash script

I have a json in file myTime
{
"beginTime": "2014-Mar-19 02:15:00",
"endTime": "2014-Mar-29 02:00:00"
}
I want to get beginTime and change it to timestamp.
I get beginTime by the following code:
beginTime=($(jq -r '.beginTime' myTime))
I replace Mar by 03 :
beginTime=($(echo "$beginTime" | sed -r 's/[Mar]+/03/g'))
I change it to time stamp :
date -d "$beginTime" "+%s"
I got 1395162000 , it mean only change 2014-03-19 because $beginTime give 2014-03-19 , first element of array.
so I tried another code
date -d "${beginTime[#]}" "+%s"
now I got
date: extra operand `+%s'
but this code is ok
date -d "2014-03-19 02:15:00" "+%s"
Could anyone help me?
Do not use array variables - you need to capture date and time as a single string:
beginTime=$(jq -r '.beginTime' myTime | sed 's/Mar/03/') # "2014-03-19 02:15:00"
Note that I've combined your first two commands into one.
(As an aside: regex /[Mar]+/ happens to work in this case, but is not what you intended - use /Mar/ instead. /[Mar]+/ matches any span of at least length 1 composed of any of the following characters in any sequence: M, a, r.)

Resources