pass variable to strtotime in php
Clash Royale CLAN TAG#URR8PPP
pass variable to strtotime in php
My question is that when I get the time duration for example 15 min. duration per hour in database and these value store in variable and then these variables are passed to the strtotime("+15 minutes") then they get error. How do I solve this problem?
My code is here:
$custom = $book_u['custom_min'] = $row['custom_min'];
$start_time=explode(',',$row['start_time']);
while($t==0)
$t=1;
$endTime2 = strtotime("+1".$custom."minutes", strtotime($endTime));
$starts_t=date('h:i a', strtotime($endTime));
$ends_t=date('h:i a', $endTime2);
//echo date('h:i a', strtotime($endTime)).'-'.date('h:i a', $endTime2).'</br>';
$endTime=date('h:i a', strtotime("+15 mins", $endTime2));
if(strtotime($endTime)>strtotime($finalTime))
$t=1;
else $t=0;
1 Answer
1
The strtotime()
function will generate a timestamp which equates to the number of seconds since January 1 1970 00:00:00 UTC, relative to the timestamp.
strtotime()
So your input into the function must always be a value that contains at least a date. Using just a time value will cause you problems.
Here is an example of how to use the function:
$endTime = '2018-08-10 22:00:00'; //End time must be a date reference.
//Using just a time like 22:00:00 will cause you problems.
$custom = '15'; //Number of minutes
$end_t = date('h:i a', strtotime($endTime . ' +' . $custom . ' minutes'));
//Notice where the spaces are. The strtotime() part will read "2018-08-10 22:00:00 +15 minutes"
echo $end_t; //outputs "10:15 pm"
facing this error This page isn’t working dogselan.com is currently unable to handle this request. HTTP ERROR 500 not working this code brother any other solution
– abbas shah
Aug 11 at 13:24
i am trying this code but its not working any one can help me? $startTime = "01:00 PM"; $finalTime="04:25 PM"; $custom = 20; $endTime=$startTime; $t=0; while($t==0) $t=1; $endTime2 = date('+' . $custom . ' minutes', strtotime($endTime)); //$endTime2 = date('h:i a', strtotime($endTime . ' +' . $custom . ' minutes')); $array = date('h:i a', strtotime($endTime)).'-'.date('h:i a', $endTime2).'</br>'; $endTime=date('h:i a', $endTime2); if(strtotime($endTime)>strtotime($finalTime)) $t=1; else $t=0; $test = $array; print_r($test);
– abbas shah
Aug 11 at 13:36
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
whats the error your getting
– prasanna puttaswamy
Aug 11 at 5:37