How to add "N" days to smarty variable? - prestashop

I need increase a date to smarty variable. This will not be to increase the days of a current date as smarty.now if not rather to increase the days to a order date variable.
For current date the code works:
{assign var="estimated_days" value=$smarty.now|date_format:"%u"}
{"+5 days"|strftime|date_format:"%A %e %B"}
But using this formula in to variable it not working because shows wrong dates:
{assign var="estimated_days" value=$order.details.order_date|date_format:"%u"}
{"+5 days"|strftime|date_format:"%A %e %B"}
I tried with {"order.details.order_date +5 Days"|date_format:'%A, %e de %B'} and multiple formulas and the conclusion is the right order_date only is showned with {$order.details.order_date} variable in format 10-10-2021 but when is added the |date_format the captured date is as smarty.now (current date) and not the order date.
Maybe {assign var="estimated_days" value=$order.details.order_date|date_format:"%u"} is wrong?
How can I add X days in to smarty variable {$order.details.order_date} using date_format ?

This should do the trick:
Adding a day to a variable:
{assign var="estimated_days" value=$smarty.now|date_format:"Y-m-d"}
{"$estimated_days +1 days"|strtotime|date_format:"Y-m-d"}
Smarty: current day
{$smarty.now|date_format:"%A, %B %e, %Y"}

Related

How do I run an access query to pull only records with the current month from a date that is formatted as a short text?

I have some tables that I cannot modify and a field "STAT_DATE" that is formatted as a short text like "yyyymmdd". I tried the Month(now()) functions and this did not work because the field is not in date format. I have also tried using the mid and monthname functions to try and match the current months name with the name of the digits that are meant to be the month in the string.
Use Like to compare your date text to the current date formatted as 'yyyymm\*'
Here is an Immediate window session to demonstrate the technique:
' give STAT_DATE today's date ...
STAT_DATE = "20220913"
' display today's date as the yyyymm* pattern ...
? Format(Date(), "yyyymm\*")
202209*
? STAT_DATE Like Format(Date(), "yyyymm\*")
True
Then use that approach in a query:
SELECT y.*
FROM [Your Table] AS y
WHERE y.STAT_DATE Like Format(Date(), 'yyyymm\*');
If you're using ADO/OleDb to run your query, use % instead of * as the wildcard:
WHERE y.STAT_DATE Like Format(Date(), 'yyyymm\%');

Is there an R function for changing a strange character date to POSIXct?

My date type looks like 7-Feb-20 (character) data, and I need to convert this into a data/time, so eventually I can use "As.Date() or as.POSIXct()" to move it into the SQL server as datetime. SQL server uses datetime as default when moving from R to SQL.
The as.Date() function will convert character data into a date format.
You can specify the input format by using the format = argument.
In this case, it looks like your format is %d-%b-%y
%d will give you day
%b will give you abbreviated month name (compare with %B, which gives full month name)
%y will give you two-digit year.
You will also need to include the hyphen in your format.

Selecting week / ISO week number from a date/time field

Sorry - this may be a basic question, but I have been banging my head against this for a week.
I have a database field with the format "dd/mm/yyyy hh:mm:ss" called UpdateTime and referencing max(AuditHistory.ActionedDateTime) in the database.
I am trying to identify the Week / ISO Week from the date part of this field only using the dataset in ReportBuilder3.
I am trying to achieve an integer entry in a column called "WeekNo" giving me the week of the year that a transaction was made so I can use this for grouping results by year | by week number on a report for senior management.
I have tried many combinations of:
,DATEPART(WEEK,DAY(max(AuditHistory.ActionedDateTime)) AS WeekNo and
,DATEPART(WEEK,MONTH(max(AuditHistory.ActionedDateTime)) AS WeekNo.
If I use a static date, e.g. , DATEPART(WEEK,DAY('1900-01-20')) AS WeekNo, it returns perfectly as "4" but I cannot for the life of me get the datepart format correct to identify the week from the format of the field.
I believe my issue is getting SQL to accept that the field is "dd/mm/yyyy hh:mm:ss" and work out the week from the date element.
Before I go mad - I thought I'd ask if there is a quick way to achieve this.
The DATEPART function expects a date / datetime / datetime2 value. You are passing in an integer representing the day or month number.
Assuming you're storing your dates correctly, you just need to pass in the date value directly:
DATEPART(WEEK, Max(AuditHistory.ActionedDateTime)) As WeekNo

Convert day of year & year to date Big Query

I have some data which instead of having a date field, contains the day of the year as a number and the year as a number in different columns.
I have tried using big query functionality PARSE_DATE to achieve this by using PARSE_DATE("%Y %j", "2020 258") but this does not work.
When checking the docs https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#parse_date %j is not supported with PARSE_DATE.
Does anyone know how I can get around this?
For reference, the following query is as close as I can get:
SELECT PARSE_DATE("%Y %j", "2020 258") which returns 2020-01-01
You can use a brute force method, by adding the number of days to the beginning of he year:
select date_add(parse_date('%Y', split(yyyyddd, ' ')[ordinal(1)]),
interval cast(split(yyyyddd, ' ')[ordinal(2)] as int64) - 1 day
)
from (select '2020 258' as yyyyddd) x;
PARSE_DATE() does not support all format elements. As the documentation (rather defensively) explains:
The format string fully supports most format elements except for %Q, %a, %A, %g, %G, %j, %u, %U, %V, %w, and %W.

Not able to get month from current date

Am trying to extract month from the current date but in vain. I am using the code:
Format(Today.Date, "mmmm")
However when I try to run it to display month like January it instead displays 00. I thought that this would work but it isn't. What can I do to get the month from current date in vb.net using a simple approach like a single function?
Try This :
DateTime.Today.ToString("MMMM")
Check out This for detailed date formatting options.
try this
MonthName(Now.Date.Month(),true)
msdn: Custom Date and Time Format Strings
Format(Today.Date, "MMMM")
EXTRACT(MONTH FROM NOW()) , getting month of current date