The timezone could not be found in the database

Silverstripe Version: 4.1

Question:
I’m getting this error:

# [Emergency] Uncaught Exception: DateTime::__construct(): Failed to parse time string (DateSent) at position 0 (D): The timezone could not be found in the database

### GET /dev/build?flush=&flushtoken=8fd6d0546531f38d5b89578d12c21608

Line  **23**  in  **/var/www/html/vendor/silverstripe/framework/src/Core/Injector/InjectionCreator.php**

When running an dev/build on a new DataObject. It’s $db is set up as:

private static $db = [
	'Type' => 'Varchar',
	'To' => 'Varchar',
	'Subject' => 'Varchar',
	'Content' => 'HTMLText',
	'Sent' => 'Enum(array("yes", "no"), "yes")',
	'DateSent' => 'DateTime'
];

My PhpInfo has a timezone set of “Pacific/Auckland”. MySql variable for timezone is “SYSTEM”.

I’ve added SS_DATABASE_TIMEZONE = “Pacific/Auckland” which didn’t work so I tried “+12:00” which still didn’t work after dev/build?flush.

Any ideas?

Hi Lance,

I believe you’ll need to use either "Datetime" or "DBDatetime" (case is important here!). With "DateTime", it’s trying to create an instance of PHP’s native DateTime class, rather than SilverStripe’s model class.

Loz

2 Likes

Thanks you were right. Capital T killed it.