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

NitinSP created an issue. See original summary.

NitinSP’s picture

Issue summary: View changes
gg24’s picture

Hi @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!

NitinSP’s picture

Hi @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?

damienmckenna’s picture

Status: Needs work » Closed (won't fix)

Per 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.

mayc1030’s picture

I worked by getting the value of the date as follows $node->field_date->date->getTimestamp();

leymannx’s picture

@mayc1030 – Bless you! This has taken me ages!

tce’s picture

@mayc1030 – Thanks. It works 👍

slivorezka’s picture

Also, this code works for me:

$node->get('field_date')->getTimestamp();