SMARTY - how to add days in variable to date? - smarty

I want to add to $order->date_add which is date, additional days. Number of days is in variable $order->days
i have code like this
{$order->date_add|cat:' +60 days'|date_format:"%d-%m-%Y"}
but i want to replace number '60' by variable $order->days. Unfortunetly i can't do it in php - I must make it in smarty. Is it possible? How to replace that 60 by variable?

In what format do you have a date in {$ order-> date_add}?
If there is a timestamp, you can do this:
{$order->date_add+20*24*60*60|date_format:"%d-%m-%Y"} //+20 days
or
{$order->date_add + $order->days|date_format:"%d-%m-%Y"} // + {$order->days} days

Related

convert Calendar date to Julian Date in Unix

I have one requirement. in one of the source file I'm getting calendar date as input and while processing the file it has to convert Julian Date format. I just need a Script.
ex:Date: 10-Nov-2020
Julian Date: 2020314
The easiest way is
date -d 10-Nov-2020 +%Y%j
but it seems to count from 1, not 0, so it returns 2020315.
Perl's Time::Piece can be used to get the expected value:
perl -MTime::Piece -lwe '$t = localtime->strptime(shift, "%d-%b-%Y"); print $t->year, $t->yday' -- 10-Nov-2020
You might need sprintf "%03d", $t->yday instead of just $t->yday if you want 2020000 instead of 20200 for the first day.

Add custom letter to timestamp instead of month in shell or perl

So, I am not a coder but i have to write a shell script that can "call" a timestamp in format [A][21][16][30][4] where A is the Month (A for January, B for February, C for March and so on), 21 is the day, 16 is the hours, 30 is the minutes and 4 are the tenth of a milisecond (0-5). Brackets are only for visualization, so the timestamp should be A2116304
This needs to be either a shell script or a perl code, that is part of a shell script (i need to put this is an existing shell script).
I tried searching for solution, but couldnt find anything useful.
The idea is that i need to append this custom timestamp to a file name, like
FILENAME.TIMESTMAP
Thanks !
Assuming that:
time is now,
time zone is GMT,
you want a fixed length timestamp,
the last digit should be tens of seconds.
I suggest something like:
my ($s, $m, $h, $D, $M) = gmtime;
my $prefix = "snapshot";
my $filename = sprintf "%s.%s%02d%02d%02d%d",
$prefix, chr($M+ord "A"), $D, $h, $m, $s/10;
print $filename, "\n";
Output:
snapshot.J2612182
You can use localtime instead of gmtime if you don't want to use GMT.
Both *time functions take a UNIX timestamp as argument, in case you need something other than now.

Generate line number / "index" within a range from a date seed value

I'm trying to create a bash script to display a word of the day. I have a dictionary file that on each line has a word and its definition.
I'd like to use date to get a unique value for each day. Like so
today=$(date '+%Y%m%d') # will return 20160616 (for today)
Now I'd like to use this value to generate a line number for me to grab from the dictionary file.
My dictionary is 86036 lines long so I need to convert $today to a value between 1 and 86036.
What is the best way to do this?
You can use remainder operator %, it will give value between 0 and the number on the right (not inclusive), so you need to add 1 to get what you want:
value=$((today % 86036 + 1))

Oracle date calculation issue

there is a requirement like below:
string format is : dd hh:mm:ss, this means (days hours:minutes:seconds, day is optional)
now the string will add to value "1/1/4000", so if the incoming value is "00:15:00" the resulting value would be 1/1/4000 00:15:00 (add 15 minutes to 1/1/4000). If the incoming value is 2 00:15:00 then the resulting value would be 1/3/4000 00:15:00 (add 2 days and 15 minutes to 1/1/4000) . If the incoming value is 32 00:15:00 then the resulting value would be 2/1/4000 00:15:00.
so is there any simple method to implement this requirement above?
You can convert your input string to INTERVAL DAY TO SECOND datatype using TO_DSINTERVAL and then add it to your default date. The result will be a date.
date'4000-01-01' + TO_DSINTERVAL('2 23:23:12');
But this requires your input string to be in DD HH:MI:SS format. Since in your input, day is optional, you should append 0 days to the string, in case it isn't present.

CodeIgniter making the date helper output 12 hour format

Using the Ci date helper, how would I turn '06/08/2012 17:10pm' into 12 hour format?
date('m/d/Y H:ia ', strtotime($row->entryCreationDateTime))
That code has nothing to do with CodeIgniter, it's simply PHP functions. For information on the date function, see the manual page.
The small chatacter h puts the hour in 12-hour format and capital chatacter H puts the hour in 24-hour format.
Change the code to this:
date('m/d/Y h:ia ', strtotime($row->entryCreationDateTime))

Resources