Questions tagged [datetime]

Use it for questions about handling date or time through any module. Don't use it if you are already using "calendar" as tag.

Filter by
Sorted by
Tagged with
1
vote
1answer
23 views

How to change the date format in the date field as a select list?

On user registration page, I have added a date field in select list. In the manage form display tab, I can set the order of the dropdown fields like day/month/year or month/day/year But I am unable ...
0
votes
2answers
41 views

How do I programmatically save “2019-11-04 07:30:00+01”?

I have "2019-11-04 07:30:00+01" as datetime value. I am not getting how to handle the "+1" part in a Drupal 8 date field. I am using this code, but it's not giving me any value. use Drupal\Core\...
0
votes
1answer
21 views

Combining Date Start and Date End in Drupal 8 Views Block

I am new to Drupal 8 Views - How do you concatenate Event Start Date Sept 1, 2019 with Event end Date ie: Sept 4, 2019? The end result is they just want the Month and Day to show up like this Sept 1-4....
0
votes
1answer
33 views

Views date exposed filter by year in checkboxes

I have date field. In views I want to add the a date exposed filter. This filter will only display year and we can select multiple years. Just like this I have checked the better exposed filter ...
0
votes
1answer
43 views

Filter excludes date in end date field

I have a view in Drupal 8 as below. [The date column in below list, is not an event. its order item. so date showing is order complete date only] When I filter with start and end date, the data shown ...
0
votes
0answers
39 views

How to show date as “XX ago” (only two digits) in comments/node/taxonomy/blocks? [duplicate]

This code works for comments but I need to display the date in two digits (XX minutes, XX hours, X year) not as "XX hours XX minutes" for example. And I need to apply this format for the rest of the ...
-2
votes
1answer
58 views

Calendar/datepicker popup not working on safari

Below is the date type form field I have in some form which renders on chrome correctly. $form['date']['air_date'] = array ( '#type' => 'date', '#title' => t('Air Date:'), '#required' =&...
0
votes
0answers
24 views

Views exposed date filter range format

I have a view with an exposed filter for a date range. I use jquery ui datepicker to select dates. It works good and I can select dates in spanish format (dd/mm/yyyy). But when I apply the filter, It ...
1
vote
0answers
26 views

Instantiate DateTime with localized time [duplicate]

I'm trying to migrate some data from MySQL DateTime format. Here's one: $old_date = "2019-05-06 08:00:00" My content type has a custom field using DateTime. Using the info from SO links below, I ...
3
votes
1answer
80 views

Date input format problem

I need to import a large dataset (over 300,000 records) into a Drupal 8 site. I have figured out how to do this with feeds on a small test dataset. The dates in the records are in the format June 8, ...
0
votes
0answers
17 views

How to refer to the node created date in Computed Field PHP

I am using the Computed Field module in D8. I am trying to compute some dates using the node created date as the start point. As my first try, this code works: $valuein = $entity->field_datefield-...
0
votes
1answer
149 views

Format date field in twig

Date field having multiple values. Need to format the output. {% for item in items %} <div{{ attributes }}>{{ item.content|date(format="F j, Y") }}</div> {% endfor %} item.content ...
0
votes
1answer
28 views

How do I create a time range form field?

Is there any way to add time range input fields in a form, for example using code similar to the following one? $form['notification_hours'] = array( '#type' => 'time_range', // type time_range ...
-1
votes
1answer
91 views

Get difference between two dates programatically

In summary: On a Drupal 8 project, i am trying to programatically get the difference between two different times (current time - Node creation time) Use case: I have "nodeabc" already available on ...
0
votes
1answer
31 views

Filter a view with contextual authored date

I have a Drupal 8 view where I want to sort nodes by authored year using contextual filters. So www.mysite.com/2017 will list all nodes from 2017. I set up the filter using 'Content: Created Year' ...
1
vote
1answer
34 views

Upgrade breaks Rest Export View in Calendar [closed]

We have a website that uses Views with a serializer rest export to display events on a monthly calendar. When we upgraded from 8.6.16 to 8.7.3 the calendar display is blank. All the json information ...
0
votes
0answers
29 views

Drupal Event Calendar module - Can I make the end time of an event dependent on another field?

I am using the Event Calendar module to create "music classes" for a school of music. They have three levels of classes: Beginner - each class is 30 minutes long Intermediate - each class is 40 ...
0
votes
0answers
17 views

How to declare field type DATETIME and set the default value

I have a problem but with the following code. I am creating the following Schema: $schema['billfold'] = [ 'description' => 'Stores example person entries for demonstration purposes.', '...
-2
votes
1answer
66 views

Can I use Moment.js to fix a client side date format issue?

Different Browser and OS show a different date format on client side. Given the following markup: <input data-drupal-selector="edit-field-date-end-value-date" title="Date (e.g. 2019-05-15)" type="...
1
vote
0answers
39 views

How to create a pair of dates (date_combo) using the Form API?

The Date module provide a field type called date_combo that allows a date feld to collect both a start date and an end date. It works as expected when I use the GUI to create a content type with a ...
0
votes
0answers
15 views

How do I use the DateFormatter? [duplicate]

I am trying to use the DateFormatter so I can convert my unix time-stamp into a usuable date stamp that will be set on a custom form. This is my code: $time = \Drupal::time()->...
0
votes
1answer
36 views

How to use date_date_callbacks

In Datetime.php from Core\Datetime\Element, I read: #date_date_callbacks: Array of optional callbacks for the date element. Can be used to add a jQuery datepicker. What does it mean? How am I ...
-1
votes
2answers
401 views

Convert current time from Unix timestamp to date format (d/m/y)

In my custom module (.module) file, I am using: $current_time = \Drupal::time()->getCurrentTime(); date_default_timezone_set('GMT'); to get the current date... However, the date value is returned ...
0
votes
0answers
16 views

How to order datetime items chronologicaly on save

Is there a module or a simple way to order a multipe datetime/datetime_range field chronologicaly on every save? I want to be sure that the last item is always the last one.
0
votes
2answers
74 views

Date/Time not saved correctly?

I made a date range field, and after entering some values and saving on first glance it looks ok, if i entered 20:00:00h it will display the same, but in the DB when i look at the stored values it's -...
0
votes
0answers
23 views

How to restrict dates in the form widget?

I am attempting an upgrade and I am looking for something that mirrors the functionality of the Date Restrictions module Basically, I used it to set relative limits,, something like no earlier than ...
2
votes
1answer
50 views

No default value for '#type' => 'date'?

is there a way to configure a date form so it has no default value? Setting the default value to NULL sets the default value automatically to the current date. /** * @return array */ public ...
0
votes
1answer
26 views

custom module date formatter for publication date

I have a Drupal 8 contrib module AP Style Date that provides a formatter for dates to conform to the AP Style Guide date rules. When using the module Publication Date, this formatter does not come up ...
0
votes
1answer
31 views

Rules add date variable from webform submission

I have a webform where the user also submits date. I would like to populate a date type field with the submitted date. I tried making variable by "Add variable", but I do not know how to access my ...
2
votes
2answers
483 views

Date vs Timestamp field-type

My new project involves the requirement of manually setting a time of creation of nodes because they're looking into manually migrating parts of their old website into their new one. The date will ...
0
votes
0answers
86 views

Why is a ISO:8601 date within a time tag converted to zeroes?

I've been attaching Timeago script to my themes and it requires dates to be formatted like this. <time class="timeago" datetime="2008-07-17T09:24:17Z">July 17, 2008</time> In a view, I ...
0
votes
1answer
130 views

Upon submitting a webform, set a date field on the article node equals to “current time” + “X minutes”

I am using the Field Timer module to display countdown timer on my article node. This module will take the value of the date/time field (my case: field_article_datetime) and convert it into a ...
1
vote
1answer
167 views

Set a date field equal to “current time” + “5 minutes” using tokens

I am using the Field Timer module to display countdown timer on my article node. Say my article node has the date/time field named (field_article_datetime) This module will take the value of the ...
1
vote
1answer
35 views

How to show the following n events with respect to the current date or the past events to always ensure n elements in the view?

I have an agenda on my homepage, and I want to always ensure 5 events. If there are 5 or more following events (including the current one), show the nearest 5 from the start date. If there is less, ...
0
votes
1answer
37 views

Serializing dates

In Drupal, we have the time printed as "2012-03-19 07:22". What I need is just "\/Date(1198908717056)\/" or just "1198908717056". I am trying to get that format using the following code. use Drupal\...
1
vote
1answer
46 views

Create Custom Date Formatter for Date Posted Field

I followed a very helpful article by Antonio Benitez that gave some example code showing how to create a custom date formatter for date fields (How To Create a Custom Format for a Date Field). The ...
1
vote
2answers
454 views

Control Webform's date field (datepicker) from JS

I have to change number of months that's shown in datepicker of my date field in Webform, on desktop I need 2 months, but on mobile just 1. I'm not able to control that using JS, so I created patch ...
0
votes
0answers
116 views

How to combine two date fields and alter its value programmatically based on field value?

I have two fields field_start_date and field_end_date and under manage display section I have set the field format for field_start_date as F d field_end_date as - d Y I need to combine the two fields ...
0
votes
1answer
44 views

Let customers set appointments while showing me their country time and my country time in contact form output [closed]

I'd like to create a form in which a customer will insert basic details like name, email and so forth but will also schedule a specific date and time in an appointment scheduling system, adjusted to ...
0
votes
1answer
38 views

Datelist element in webform not working

I was just going through webform configurations and I changed the date list element format from default to raw. After doing this Im not able to add any element of type dateform to my webform and also ...
1
vote
0answers
24 views

How do I access datetime field formatter node values?

The DateTimeFormatterBase class is performing a ->setTimeZone incorrectly for my use case. How do I access the node values from where the $date passed to setTimeZone originated? Strange question I ...
0
votes
0answers
17 views

Copy Field Collection Data to Date Range Fields?

When our Drupal 8 website launched we used the Field Collection module so that some content types could store two or more dates for calculating a range, something not then supported on the platform. ...
0
votes
1answer
25 views

Display the exclude dates on a node

I have a Drupal 7 site with a content type called Weekly Repeating Event, and events of this type repeat at the same time and day each week. I use a custom template file to display this node type by ...
0
votes
1answer
680 views

How to print “Time” field in twig template

I have a time field in my content type. But when I entered time in the format 05:00 AM, I get a five digit timestamp eg. 18000 (for 05:00 AM). When I print this using node.field_time.value|date('h:i ...
0
votes
0answers
30 views

Need system wide time zone calculation ability

I need to hook into the time zone pipeline before date display to properly calculate "local" time events. It seems Drupal provides site and user time zone settings (and Views has its own TZ control ...
6
votes
2answers
683 views

My Date in Twig is ignoring format

I have a twig file with the following code in my Drupal 8.4.4 site: <div class="value col-md-12">{{ node.field_date.value }}</div> And in my content type, manage display option, I have ...
0
votes
1answer
124 views

Update the date field to the date & time of the node being updated

I am sure that I am missing something very simple here, so I hope somebody can put me on the right track. Use Case: I have a simple content type "Article" A date field of type: "Date and Time" is ...
1
vote
1answer
90 views

View date filter using years as an offset

Is there a way to use years as a date filter offset? What I want is to set it so that it it loads all content from the start of the previous year. So >= 01-01-2017 this year, >= 01-01-2018 next year, ...
1
vote
0answers
49 views

How to set a default date when extending DateRangeItem FieldType plugin

I created a new field type plugin that extends DateRangeItem. My plugin only adds some more settings. I also created an own widget that extends DateRangeWidgetBase. My formElement function looks like ...
1
vote
1answer
73 views

Date/Time +1h in Node

I have a module to import nodes with a date/time field. All times are correctly written into the database. But when I view a node or in node/edit I get the time +1 h. In Drupal I have set the timezone ...