Strange behavior with localizeddate filter in Twig - date

In Twig, I have a DateTime like that (from a dump):
DateTime {#22261 ā–¼
+"date": "2017-01-01 08:00:00.000000"
+"timezone_type": 1
+"timezone": "+01:00"
}
When I print this date with different filters, I get different results for the year.
Examples :
{{ testdate|date('d M Y') }}
prints 01 Jan 2017 => Year is correct.
{{ testdate|localizeddate('none', 'none', "fr", "Europe/Paris", "d MMM YYYY") }}
prints 1 janv. 2016 => Year is wrong.
{{ testdate|localizeddate('medium', 'none', "fr") }}
prints 1 janv. 2017 => Year is correct.
So when I use localizeddate('none', 'none', "fr", "Europe/Paris", "d MMM YYYY") the year seems to be wrong.
If I change locale to "en", the year is now correct (2017). But if I try in other locales like "de", "it", "es", "pl" year is always "2016".
Note : Same results if I let null for timezone parameter.

http://userguide.icu-project.org/formatparse/datetime
You must use 'y' instead of 'Y'.
With 'Y' you will show the year of the week, but with 'y' you will show the correct year.
Sometimes, a short week in january is considered part of december (week 52 or 53) and vice versa.

Related

Date listing at postgresql

and date(p.date_of_sale) <= current_date
I try this code and I got an answer like that.
.
But an error is shown like that.
.
Please watch 2 screenshots because I am not fluent in English and I don't know how to explain with text. That's why I add 2 screenshots.
Your problem comes from to_char(p.date_of_sale, 'yyyy "-week" iw') where
iw = week number of ISO 8601 week-numbering year (01ā€“53; the first Thursday of the year is in week 1)
whereas yyyy = the year on 4 digits (not the ISO8601 year)
These two parameters are sometimes not consistent for instance for 2023 January the 1st :
SELECT to_char('20230101' :: date, 'yyyy') => 2023
SELECT to_char('20230101' :: date, 'iw') => 52
If you want to be consistent, you can either :
select to_char('20230101' :: date, 'YYYY"-week" w') => 2023-week 1
or
select to_char('20230101' :: date, 'IYYY"-week" iw') => 2022-week 52 (ISO8601 year and week)
see dbfiddle

How to use formatDateTime in Azure Data Factory?

I would like to format the pipeline trigger time in this format:
10-Mar-2021 08:31:59 AM
Here is the code I am using:
#formatDateTime(pipeline().TriggerTime, 'DD-MON-YYYY HH:MI:SS AM/PM')
However the date is coming out in this format:
'DD-3ON-YYYY 08:3I:SS A3/P3'
How can I resolve this?
The formatDateTime function uses the custom date format strings which you can see listed here. A detailed breakdown
dd - the day of the month from 01 to 31. Note this is lower case and this format gives a leading 0. Using d for no leading 0
MMM - the abbreviated name of the month, eg JAN, FEB, MAR. Note this is upper case
yyyy - the year as a four-digit number. Note this is lower case
hh - the hour using a 12-hour clock from 01 to 12. Note this is lower case. As you are using AM/PM it makes sense to have the 12-hour clock rather than 24 (ie 23:00 PM would not make sense). Note this is lower case
mm - the minute from 00 to 50. Note this is lower case
ss - the second from 00 to 50. Note this is lower case
tt - the AM/PM designator. Note this is lower case
So using this information, your code should be more like this:
#formatDateTime(pipeline().TriggerTime, 'dd-MMM-yyyy hh:mm:ss tt')
I have test the expression using a Set Variable activity and got the following results:
EEE : Day ( Mon )
MMM : Month in words ( Dec )
MM : Day in Count ( 324 )
mm : Month ( 12 )
dd : Date ( 3 )
HH : Hours ( 12 )
mm : Minutes ( 50 )
ss : Seconds ( 34 )
yyyy: Year ( 2020 ) //both yyyy and YYYY are same
YYYY: Year ( 2020 )
zzz : GMT+05:30
aa : ( AM / PM )

Date format does not work in R

This is my date column which is on my dateframe:
data <- data.frame(year_month = c("2015-01-01", "2015-02-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-06-01"))
class(data$year_month)
[1] "factor"
I tried:
data$year_month1<-as.Date(as.factor(data$year_month), format="%b %Y")
I want:
" Jan 2015", "Feb 2015", "Mar 2015", "Apr 2015", "May 2015", "Jun 2105"
What happens:
My column on data$year_month1 comes Empty.
I tried quite a few solutions that I found here but the format does not change at all or it comes empty.
Help, please>
format(as.Date(data$year_month), format="%b %Y")
#first convert to Date, without as.factor (why did you do that?)
#then convert it to character as you want it, with format()

$week mongodb to datepart(wk)

I'm exporting aggregated data to MS SQL server from mongodb
mongo's $week does not evaluate to the same week as T-SQL datepart(wk, ) or datepart(isowk, ).
Does anyone know how to test the mongodb $week function so I can do some comparisons and see how best to resolve this issue?
Any help would be appreciated.
As far as I can see the differences fall into two main areas, the plain part being described in the documentation:
Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0. This behavior is the same as the ā€œ%Uā€ operator to the strftime standard library function.
So the general concept here is that the value returned will be between 0 and 53 inclusive with week 0 being defined as the first week when the days are before Sunday.
So to paraphrase ( because the documentation gets the days wrong ) from the technet source for "datepart":
January 1 of any year defines the starting number for the week datepart, for example: DATEPART (wk, 'Jan 1, xxxx') = 1, where xxxx is any year.
And then (corrected):
The following table lists the return value for week and weekday datepart for '2007-04-21 ' for each SET DATEFIRST argument. January 1 is a Saturday in the year 2007. April 21 is a Saturday in the year 2007. SET DATEFIRST 7, Sunday, is the default for U.S. English.
So where you had documents like this:
{ "date" : ISODate("2007-01-01T00:00:00Z") }
{ "date" : ISODate("2006-12-31T00:00:00Z") }
{ "date" : ISODate("2006-01-01T00:00:00Z") }
The $week operator would return such as this:
{ "date" : ISODate("2007-01-01T00:00:00Z"), "week" : 0 }
{ "date" : ISODate("2006-12-31T00:00:00Z"), "week": 53 }
{ "date" : ISODate("2006-01-01T00:00:00Z"), "week" : 1 }
January 1st in 2006 was a Sunday and is considered the start of week 1, but where it was a Saturday it would be week 0 of 2007. The 31st of December in the previous year is Week 53.
In contrast the DATEPART considers Jan 1st 2007 and Dec 31st 2006 to be in Week 1 as the week ending on the first Sunday of the year. The Sunday is the default US English value but may differ and can in fact be set via SET DATEFIRST
So both have different opinions of where a date belongs in terms of the week of the year, but the general difference will be one with the other consideration days falling at the end of the previous year.

Zend_Date::toString() outputs the wrong year. Bug in my code, or Zend_Date?

I'm using Zend_Date to set and get the year, but it is not being set as the correct year. I set the year as 2010, and it returns the year as 2009. What am I doing wrong? Is there a bug in Zend_Date?
$date = new Zend_Date('2010-01-03', 'YYYY-MM-dd');
echo $date->toString('MMMM d, YYYY');
//outputs January 3, 2009
The year must be being set correctly because getting the year part of the date works:
echo $date->get(Zend_Date::YEAR); //2010
Solution:
Well I got it to work...You have you use lowercase: yyyy
echo $date->toString('MMMM d, yyyy');
YYYY stands for the ISO Year. 2010-01-03 is week 53, day 7 of the ISO year 2009
yyyy stands for the actual calendar year.
I've ran into this problem as well.
In the Zend_Date class 'YYYY' means to a 4 digit representation of the 'ISO year' where as 'yyyy' means a 4 digit representation of the 'year'.