Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
0answers
24 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
14 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
24 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 ...
0
votes
0answers
13 views

How to get the value of a date field in Drupal 8? [duplicate]

I know how to get the value of a field using the code below :- $entity->get('field_name')->getValue(); But how to get the value if the field type is "date"?
0
votes
2answers
47 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
15 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
39 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
20 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
47 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
20 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
14 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 ...
1
vote
2answers
104 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
77 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
45 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
63 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
30 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
33 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
31 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
89 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
58 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
41 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
22 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
23 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
13 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
18 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
249 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
27 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
589 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
78 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
46 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
44 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
68 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 ...
0
votes
1answer
672 views

Views filter criteria date field is greater than current date

I have a overview page with different events. Now it shows all events which were created. But I will that it just shows all the future events. The content type has a datefield for the eventdate. I ...
0
votes
1answer
17 views

Show content with a date after the current one on a view

I'm creating a calendar of events with Drupal 7 using views. At the moment the elements are shown in order of the date of each one (I have a date field where I put the date of the event). Now I need ...
0
votes
2answers
42 views

Insert date programatically in custom module

I am programatically saving values from an array $customer into a content type. The below code works fine and populates the content type customer_profile except for the field date of birth. This field ...
0
votes
1answer
48 views

Date popup field won't display in tableselect element

I am attempting to embed a couple of date fields within a tableselect element, and after trying to use both textfield and date_popup field types, I can't get either to work. Here's my form function ...
1
vote
1answer
185 views

How to programmatically set the user timezone

I am programmatically creating a user and wanted to assign a timezone for the user I am able to successfully create a user by the following code $user = \Drupal\user\Entity\User::create(); $user-&...
1
vote
1answer
33 views

Modify date popup structure

I would like to modify the date popup structure, in the image below you can see how date module builds the element. Drupal's default label is hidden, and it generates other to display the title. I ...
0
votes
1answer
154 views

How to add a time picker in datetime form elements

I have made a module that display a form. One of the form elements is a datetime field. $form['FirstDate'] = array( '#type' => 'datetime', '#title' => t('First date-time'), '#...
1
vote
2answers
96 views

Create a custom date format

Our organization's style guide expects dates in this format: Oct. 31 2018 01:30 p.m. I looked the date format drop-down in our views, and there were several options, including a custom one. ...
1
vote
1answer
36 views

Get all the machine names of the date formats

I have searched the Drupal documentation but until now I have not found the way to obtain the machine names of the date formats that the user creates from the Drupal administration. They would be the ...
0
votes
0answers
26 views

Why does changing date portion of a datetime string on node presave subtract an hour from the time portion?

I have two date fields, one only accepts date input and the other is only accepting time input (via the technique where you set the ['#date_date_element'] = 'none' as described in this answer). In ...
0
votes
0answers
26 views

Change date field; how to add timezone handling later

About date fields, this page https://www.drupal.org/node/767182 says If you start off without a time zone, but then realize that you need one at a later date [...] Perform the switch in the ...
1
vote
1answer
37 views

Get all nodes where date field matches month and year

I have a content type with a date field (myFieldDate) whose values are timestamps. (I'm collecting only day, month, and year.) I have a custom form where I have a select list to select month and year....
0
votes
1answer
190 views

Import date field with feeds

I have a csv with a Date field that contains the date in one of the following formats: dd/mm/yy (ex. 13/11/04) dd/mm/yyyy (ex. 13/11/2004) I need to import these dates to my field in the format dd-...
0
votes
1answer
204 views

How can I get translation for a field of custom date

I am using the paragraphs module. I have a field which contains a date and time e.g. for events, which is added by an author. For the output I use a paragraph-twig-file and I have this: <div class=...
0
votes
1answer
549 views

Migration Source YML File import date string into date and time field of content type

I have a json file full of data exported from a wordpress site, one field being a string representing a date and time: "03/15/2012 14:46:19". I would like to import that string into a date and time ...
1
vote
1answer
152 views

How to retrieve value of start date with format end date?

I D8 installed the module Optional End Date in order to add an optional end date within a date field. When I had a single date field value I could get the value by using: $datum_deelname = $node-&...
0
votes
1answer
157 views

entityQuery with multivalue date field

Is there way to use entityQuery in order to select nodes with multiple value date field. For example we have a content type event with a field field_event_date which may contain unlimited number of ...
0
votes
1answer
245 views

Change the format of 'Authored on' date in views filter

In Drupal 8, I want to remove the timestamp on 'Authored on' date in views filter. Any Idea how to do this?