I have spent too many days & nights reading through documentation and trying just about anything to get this to work.
I have implemented this datetime picker for a website's contact form so users can make reservations and in turn the server will send an .ics calendar request to the owner for his records: https://mugifly.github.io/jquery-simple-datetimepicker/
The datetimepicker is configured via jquery.simple-dtpicker.js to have format: 'DD-MM-YYYY hh:mm' for both available languages, en & es for English and Spanish. The reason is the website is Spanish.
Up to here everything works great and I get a datetime value sent through when testing the contact form.
My issue is SIMPLY trying to add 1 hour to the obtained datetime in order to fulfill the required format for the .ics event in PHP.
Instead of adding an hour, it either defaults to the current local time and adds 1 hour or it defaults to 01/01/1970 (Epoch Time) and mangles the time. This is not the same outcome I get when succesfully testing the same code in online php testers.
Here is my php code:
<?php
date_default_timezone_set("Europe/Berlin");
$dateStart = $_POST['ical'];
$date = date_format($dateStart, 'd-m-Y H:i');
$dateZ = date('d-m-Y H:i', $date);
$dateDone = date('d-m-Y H:i', strtotime($dateStart + 3600));
$date1 = date('d-m-Y H:i', strtotime('+1 hours', $dateStart));
$date2 = date('d-m-Y H:i', strtotime('+1 hours', $dateZ));
$date3 = date('d-m-Y H:i', strtotime('+1 hours', $date));
And my results:
$dateStart: 20-04-2021 05:00
$dateDone: 09-04-3620 07:35
$date1: 01-01-1970 02:00
$date2: 01-01-1970 02:00
$date3: 01-01-1970 02:00
Any idea what could be the issue? I cannot use any of the datetime format/modify/add functions which use -> operator for some reason so the only thing that seems to work is adding an hour via string or integer.
Many thanks
You have made very silly mistakes.
date_default_timezone_set("Europe/Berlin");
$dateStart = '20-04-2021 05:00';
$date = date_format(new DateTime($dateStart), 'd-m-Y H:i'); // date_format need date time .. string were suplied
$dateZ = date('d-m-Y H:i', strtotime($date));
$dateDone = date('d-m-Y H:i:s', strtotime($dateStart + 3600)); // didnt get what exactly you need.. in date function you can add time easily using str to time
$date1 = date('d-m-Y H:i', strtotime('+1 hours'. $dateStart));
$date2 = date('d-m-Y H:i', strtotime('+1 hours'. $dateZ));
$date3 = date('d-m-Y H:i', strtotime('+1 hours'. $date));