I try to user $_POST variable on dateTime .
this my code
require('configDB.php');
date_default_timezone_set("Asia/Bangkok");
$conn=$DBconnect;
require __DIR__ . '/vendor/autoload.php';
$date = $_POST['date'];
$eventname =$_POST['event'];
$start=$_POST['start'];
$end =$_POST['end'];
$enddate = $_POST['enddate'];
$time_period=$_POST['time_period'];
$room_id=$_POST['room_id'];
$dateyimestart=date_create($date.$start);
$dateselectst = date_format($dateyimestart,"Y-m-dTH:i:s+07:00");
$event = new Google_Service_Calendar_Event(array(
'summary' => $eventname,
'location' => '喔腑喔涏福喔班笂喔膏浮喔涪喔膏笜喔⑧覆',
'description' => '喔佮覆喔`笡喔`赴喔娻父喔∴笚喔斷弗喔竾.',
'start' => array(
'dateTime' => $dateselectst,
'timeZone' => 'Asia/Bangkok',
),
'end' => array(
'dateTime' => '2020-03-25T16:30:00+07:00',
'timeZone' => 'Asia/Bangkok',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=1'
),
'attendees' => array(
array('email' => '[email protected]'),
array('email' => '[email protected]'),
// array('email' => '[email protected]'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
print_r($event);
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
// printf('Event created: %s\n', $event->htmlLink);
if (empty($events)) {
print "No upcoming events found.\n";
} else {
print "Upcoming events:<br/>\n";
foreach ($events as $event) {
$start = $event->start->dateTime;
if (empty($start)) {
$start = $event->start->date;
}
printf("%s (%s)<br/>\n", $event->getSummary(), $start);
}
}
What is the error?
Error is when I use $dateselectst in 'start' => array can't send variable to google calendar.
this is error
PHP Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
],
"code": 400,
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
}
Fatal error: Uncaught Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
],
"code": 400,
"message": "Invalid value for: % must be called with a String value. [DateFormatMethod]"
}
}
Something is invalid here:
$dateyimestart = date_create($date.$start);
$dateselectst = date_format($dateyimestart,"Y-m-dTH:i:s+07:00");
Make sure $dateselectst is not false. If your input or format is invalid, it will.
I'm going to close this issue out. If you're still having trouble, please feel free to re-open!
thank you so much ,i can fix my code now