Closed (won't fix)
Project:
Date
Version:
8.x-1.x-dev
Component:
Date API
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
6 Jun 2017 at 13:03 UTC
Updated:
17 Jun 2021 at 09:51 UTC
Jump to comment: Most recent
In node I have added one date field with date time. After that I have created one node and add value "06/05/2017 - 22:15" to date field and save it.
After that I have tried to access date field value in theme_preprocess_node() and getting different value "2017-06-05T16:45:00".
So How can I get value that I have entered in at the time of node create programatically in Drupal 8?
Please let me know if anyone work on it.
Comments
Comment #2
nitinsp commentedComment #3
gg24 commentedHi @NitinSP,
Seems like your user timezone or may be system timezone is different. Please check it once as i see there is no issue with the date-time value from date field.
Thanks!
Comment #4
nitinsp commentedHi @gg24,
Thanks for reply.
My system timezone is Asia/Kolkata and and I have setup drupal default timezone to country -UK and Europe/London.
I am using below custom code to fetch paragraph date field value
$dateStart = new DrupalDateTime($paragraph->get('field_start_date_time')->getString());
$offerStartTime = $date->format($dateStart->getTimestamp(), 'custom', 'm/d/Y H:i:s');
Is there any way to collect correct datatime value?
Comment #5
damienmckennaPer our discussion in #2613454: Port Date module functionality missing from 8.x core, the D8 branch is no longer going to be worked on, all changes should be made directly to core's datetime module. That said, we appreciate everyone's efforts, so thank you.
Comment #6
mayc1030 commentedI worked by getting the value of the date as follows $node->field_date->date->getTimestamp();
Comment #7
norman.lol@mayc1030 – Bless you! This has taken me ages!
Comment #8
tce commented@mayc1030 – Thanks. It works 👍
Comment #9
slivorezkaAlso, this code works for me: