I am trying to change the date format in Craft 3 (Entries > all entries > "post date" column) from (MM:DD:YYYY) to (DD:MM:YYYY)
At the moment it is converting it to Iso8601.
Locales are set correctly. Have searched high and low, can't seem to find anything.
You can change date format directly inside twig template.
For example:
{{ date_post|date('DD:MM:YYYY') }}
Look at official docs about twig
Related
We are looking to compare the calendar start date with the current date in flow. Currently we are pulling the start date through a filter query like this:
formatDateTime('EventDate','M-d-yyy hh:mm')
and comparing to this:
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I am getting this error currently: "Unable to process template language expressions in action 'Get_items' inputs at line '1' and column '17987': 'In function 'formatDateTime', the value provided for date time string 'EventDate' was not valid. The datetime string must match ISO 8601 format."
Any help on this would be greatly appreciated!
You could Initialize a variable like the following below and then do a IF condition.
#{add(div(sub(ticks(utcNow()),ticks('1900-01-01')),864000000000),2)}
I test with the same formula to convert event start date and it works fine in my end. The if condition returns correct result on different conditions.
Here is the logic of my demo flow, please have a check:
I use get item to get the start date of a certain event in the calendar list and convert the start time dynamic content to the format I need. Almost same with yours.
According to the error message, it seems the format of the event date column is not in the supported format. Would you like to provide the settings of your event date column? I test with the default start time column and a custom date & time column of default settings. Both of them works fine with the flow above.
Update:
The two formulas used are displayed below:
formatDateTime(outputs('Get_item')?['body/Event_x0020_Date'],'M-d-yyy hh:mm')
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I just directly use the outputs of the data compose action in the if condition
What worked for me was to build a sequence of numbers with the dates being ordered by day, month and year this way, when converting to integer, it's easy to compare
int(formatDateTime(utcNow()),'yyyyMMdd'))
if you need add day for exemple, you can use
int(formatDateTime(addDays(utcNow(),variables('extraDays')),'yyyyMMdd'))
and the other date like this
int(formatDateTime(variables('FinalDate'),'yyyyMMdd'))
Based on your example, you can put hours and minutes without any problems, just remove the special characters and spaces
but by the definition of the error you are having, I believe it is because of the way you are writing the variable
I want to grab the time only from a Drupal Date Field, and render it in a twig template separately from its date.
In my twig template for Events I currently have date listed 3 ways:
{{ content }}
displays all the fields.
And the time (sourced from a Date field) displays correctly as;
28/04/2019 - 1:11
This is the correct time as per what was entered when the content was created.
On the same page, when using:
{{ content.field_date_start }}
28/04/2019 - 1:11
is also displayed corrected.
But I want to grab the time only to display separately from the date
so I put this in the twig:
{{ node.field_date_start.value|date("g:ia") }}
which displays as:
3:11am
This is incorrect, off by 14hours (the 1.11 when entered was 1.11 pm)
How do I separate the time to a separate display within twig, but also retain the correct time as per how it was entered.
How do I enter that into a twig?
I don't want the time to change if people are entering content or viewing content in different time zones.
Example - someone creates content in Melbourne, Australia and someone else views it in London, England - the time should display the same regardless.
Drupal saves dates in the database as per the UTC timezone. E.g If you enter 09:00 AM as the time as a user who has a timezone of London (UTC + 1) selected in the profile, it is saved as 08:00 AM in the database. Same is true if the site's timezone is set to London (UTC +1).
I would suggest preprocessing the field and setting a variable for the start time.
function HOOK_preprocess_node(&$variables) {
$node = $variables['elements']['#node'];
$timezone = drupal_get_user_timezone();
$formatter = \Drupal::service('date.formatter');
$field_date_start = $node->get('field_date_start')->getValue()->getTimestamp();
$time = $formatter->format($field_date_start, 'custom', 'g:ia', $timezone);
$variables['start_time'] = $time;
}
And then print the value in the template as
{{ start_time }}
I have an array of objects which i am displaying as a line graph in kendo.
The category axis is a date and is data between a large period of time. I want to display this date neatly (In the UK/ Rest of world date format). However i cannot seem to get this to work. Here is my HTML code below
<kendo-chart [transitions]="true">
<kendo-chart-axis-defaults [majorGridLines]="{ visible : false}">
</kendo-chart-axis-defaults>
<kendo-chart-category-axis>
<kendo-chart-category-axis-item>
<kendo-chart-category-axis-item-labels culture="en-GB"
format="d"
step="50">
</kendo-chart-category-axis-item-labels>
</kendo-chart-category-axis-item>
</kendo-chart-category-axis>
<kendo-chart-value-axis>
<kendo-chart-value-axis-item>
<kendo-chart-value-axis-item-labels culture="en-GB"
format="c">
</kendo-chart-value-axis-item-labels>
</kendo-chart-value-axis-item>
</kendo-chart-value-axis>
<kendo-chart-series>
<kendo-chart-series-item type="line" [data]="items | async"
field="cumulativePercentReturn"
markers="markers"
dashType="solid"
categoryField="startDate">
</kendo-chart-series-item>
</kendo-chart-series>
</kendo-chart>
The dates, however, are still rendered as yyyy-mm-dd etc.
The kendo for angular 2 guide is not very specific here, asking me to refer to a globalisation article which does not exist on the site.
If anyone could aid me in getting this working. I have tried editing that format string in every way i can sensibly think of.
So i solved this!
It turned out the JSON data returned was showing the date formatted as a string. The date formatting worked when i cast this string back to a date.
Im having an issue with Twig where any timestamp I pass to the date filter I always get the current date, example:
{{ 1433894400|date }}
This should return the June, 10. But instead it returns the current date.
I've tried passing a few different date formats but as expected it makes no change to the output, other than the date format itself that is.
Have anyone had this issue before?
Thank you.
By the twig docs:
The date filter accepts strings (it must be in a format supported by the strtotime function), DateTime instances, or DateInterval instances. For instance, to display the current date, filter the word "now".
Therefore, use date() to convert your Unix timestamp to a string.
I have an excel file, with a date column, but I want to convert the date column to
YY/MM/DD/Time
Ive been searching for 2 hours and no result yet.
This is my data:
Source Data: http://i.stack.imgur.com/75zbS.jpg
Expected Output: YY/MM/DD/Time
Can someone help me how I can do it? I want to insert it into postgresql and I want to change everything to compatible date format.
EDIT: I have tried Right Click -> Format cells -> date but it does not change anything!
Thanks
You could use this method and split the date and time into separate cells:
=DATE((LEFT(A1,4)),(MID(A1,5,2)),MID(A1,7,2))
=TIME(MID(A1,10,2),(MID(A1,12,2)),0)
Once your date value is in a format Excel can recognize, you can then change the formatting to whatever you'd like.
Or if you don't care to have the value in a recognizable date format, you can just get your desired formatting like this (will give you a string that looks like this: YY/MM/DD/Time):
=MID(A1,3,2)&"/"&MID(A1,5,2)&"/"&MID(A1,7,2)&"/"&MID(A1,10,4)
ISO 8601 format would be YYYY-MM-DD H24:MI:SS.
But you can set Postgres to accept various date styles by setting the datestyle setting. You can do that globally in postgresql.conf or temporarily for your session.
SET datestyle = SQL, DMY
For more exotic formats, you can create a temporary staging table, COPY to it and INSERT into your target table from there. Among others, you can use to_timestamp():
SELECT to_timestamp('13/10/14/17:33', 'YY/MM/DD/hh24:mi')
More info and example code in related answers like these:
Replacing whitespace with sed in a CSV (to use w/ postgres copy command)
How to bulk insert only new rows in PostreSQL
Your going to have to parse the date into four columns using fixed parsing.
Then reassemble the columns any way you want.
Just Google with excel parse columns fixed.