mariosimao / notion-sdk-php

A complete Notion SDK for PHP developers.
https://mariosimao.github.io/notion-sdk-php/
MIT License
150 stars 24 forks source link

[BUG] Unable to access ["date"] string #281

Closed chisoft-io closed 1 year ago

chisoft-io commented 1 year ago

Thanks for creating the Notion SDK PHP, nice work! This is only a potential bug, more likely my lack of understanding how the API works. I'm grateful for some advice.

Describe the bug I have a Notion page with a database. I'm able to retrieve various properties of the database like for expl. ->number as explained under Get page property. But I'm unable to access the ["date"] string of the Date property.

To Reproduce

$startdate = $page->getProperty("Date");
var_dump($startdate->date->start);

object(DateTimeImmutable)#156 (3) { ["date"]=> string(26) "2023-08-26 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Zurich" }

var_dump($startdate->date->start->date);

NULL

Expected behavior

echo $startdate->date->start->date;

2023-08-26 00:00:00

Code snippet See above

Environment (please complete the following information):

mariosimao commented 1 year ago

Hi @chisoft-io, thanks for using the SDK!

$startdate->date->start is an DateTimeImmutable object. It is a PHP standard object and you can find all the properties and methods exposed by this class on the official PHP documentation.

To transform it into a string, you could use the format() method. For the desired date format, I would use:

$startdate->date->start->format("Y-m-d H:i:s");