maybe if you read up on those you might find clues, or some usable code. If not, you’re better off asking in StackOverflow, this is a PHP issue… Good luck
If you are storing a date in a logic hook then you will need to set it in the database format of ‘y-m-d’ UTC. No other format will be excepted.
This is because the data in a before save logic will be ‘ready’ to just be inserted and the conversion process has already been done from user perference into UTC.
So really all you need to do is:
$comDate = date("Y-m-d", strtotime("2018-04-17")); // Which is actually redundant....
$bean->x_date_field_c = $comDate;
Now if you were pulling in linked beans and trying to convert them into a suitable database format THAT is a different task…