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
3
votes
1answer
49 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
15 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
27 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
23 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
75 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
18 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
29 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
27 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.', '...
1
vote
0answers
27 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
28 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
14 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"?
-1
votes
2answers
90 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
48 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
21 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
22 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
22 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
211 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
78 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
64 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
80 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
36 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
35 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
196 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
73 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
43 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
29 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
14 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
20 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
434 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
29 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
630 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
93 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
64 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
45 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
71 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 ...
-1
votes
1answer
1k 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
46 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
53 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
244 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
36 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
257 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
181 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
47 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 ...