Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.
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 CreditAttribution: NitinSP commentedComment #3
gg24 CreditAttribution: gg24 as a volunteer and at QED42 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 CreditAttribution: 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 CreditAttribution: mayc1030 commentedI worked by getting the value of the date as follows $node->field_date->date->getTimestamp();
Comment #7
leymannx@mayc1030 – Bless you! This has taken me ages!
Comment #8
tce CreditAttribution: tce commented@mayc1030 – Thanks. It works 👍
Comment #9
slivorezkaAlso, this code works for me: