I'm trying to run a query where a check is done if a time is in between a time and that time + 90 mins.
I have 1 time value being passed in. So lets say the time being passed in is 1pm. I'd like to check if a time is between 1pm and 2.30pm.
I have tried passing in a second param adding the seconds with strtotime() and I have the below
AND r.start_time BETWEEN '19:00:00.0000' AND '19:00:00.0000', INTERVAL + 90 MINUTE
I think you can use strtotime(...)+5400 to express 90 minutes.
For example:
$times = strtotime('19:00:00.0000');
$end_time = $times + 5400;
$query = "SELECT ... WHERE r.start_time BETWEEN '$times' AND '$end_times'";
Related
The following code will return the difference between two Carbon dates in minutes:
$carbonNow = Carbon::now();
$diff = $carbonNow->diffInMinutes($someRandomFutureDateVariable);
Which will return a single minute result. But I'm trying to get the difference in a 15 minute increments - such as every timestamp for every 15 minute increment in the result. Pseudo code would be:
[
'2020-10-15 12:45:00',
'2020-10-15 13:00:00',
'2020-10-15 13:15:00',
'2020-10-15 13:30:00',
...
]
In addition, I'd like to be able to set the time difference, so if I didn't want to target a 15 minute increment I could target whatever increment I pass into my function. I'm able to get the difference between two dates, but stuck on returning timestamps per each increment.
carbon::diffInMinutes delivers the minutes and removes the seconds.
The minute difference for a given minute increment can easily be calculated as follows:
$inc = 15; //15 minutes
$carbonNow = Carbon::now();
$diff = $carbonNow->diffInMinutes($someRandomFutureDateVariable);
$diffInc = $diff - $diff%$inc;
Need some help.
I am using PHP.
So I have coordinates data.
Specifically Longtitude and Latitude.
So let's say I have 15 data of Long and Lat to be inserted on a table.
However, the api gives me only a single datetime because these coordinates are in array.
For example:
[14.4364372;121.0125753, 14.4364375;121.0125755, 14.4364377;121.0125758, 14.436436;121.012574, 14.4364342;121.0125721, 14.4364326;121.0125704, 14.436433;121.0125707, 14.4364334;121.0125711, 14.4364338;121.0125716, 14.4364342;121.012572, 14.4364345;121.0125724, 14.4364348;121.0125728, 14.4364351;121.0125731, 14.4364353;121.0125733, 14.4364356;121.0125735]
So first you will explode it to get rid of the delimeter ','
And loop it to count how many are data,then explode again the delimiter ';' to count the long and lat given.
But it only have a single datetime.
What i want here is to insert these data including datetime but with interval of 30 seconds per insert.
How can i do that?
Expected output would be like this:
INSERT INTO table_gps(ticket,datetime,long,lat) VALUES(0,09/16/2016 03:30:26 pm, 14.4364363,121.0125745)
INSERT INTO table_gps(ticket,datetime,long,lat) VALUES(0,09/16/2016 03:30:56 pm, 14.4364364,121.0125746)
Here is my code:
$msg= 'YC GPS2~09/16/2016 13:29:46~-~[14.4364362;121.0125744, 14.4364363;121.0125745]';
if(strpos($msg,'YC GPS2')!==false){
//explode data
$explode=explode('~',$msg);
$ky=$explode[0];
$datetime=$explode[1];
$ticket=$explode[2];
$coords=$explode[3];
$coords=explode(',',$coords);
for($i=0;$i<count($coords);$i++){
$xpVal=$coords[$i];
if($xpVal){
$xp3=explode(';',$xpVal);
$lng=$xp3[0];
$lat=$xp3[1];
$lng=str_replace('[','',$lng);
$lat=str_replace(']','',$lat);
$time = date("m/d/Y h:i:s a", time() + 30);// where 30 is the seconds
echo "INSERT INTO GPS2(ticket,datetime,long,lat) VALUES(".$ticket.",".$time.",".$lng.",".$lat.") ";
}
}
}else{
echo '0';
}
Thanks.
In order to add how many seconds you want to particular date in PHP you can use the following.
$time = date("m/d/Y h:i:s a", time() + 30);// where 30 is the seconds
The following is really easy way to add days, minutes, hours and seconds to a time using PHP. Using the date function to set the format of the date to be returned then using strtotime to add the increase or decrease of time then after a comma use another strtotime passing in the start date and time.
//set timezone
date_default_timezone_set('GMT');
//set an date and time to work with
$start = '2014-06-01 14:00:00';
//display the converted time
echo date('Y-m-d H:i',strtotime('+1 hour +20 minutes',strtotime($start)));
Times can be entered in a readable way:
+1 day = adds 1 day
+1 hour = adds 1 hour
+10 minutes = adds 10 minutes
+10 seconds = adds 10 seconds
I am checking for notification update using the php time stamp difference. The activity occurred between current time & time 10 seconds before the current time i want to capture. I am using set Interval function of java-script to check on every 10 seconds. But at the script side, in php i don't know in what dimensions time stamp to increment for each seconds. How do i count the difference for 10 seconds at php side to check for notification arrived in between that time???
My java-script function is this
setInterval(function() {
$.get('<?php echo BASE_URL.'php/processing/checkForNotification.php'?>',function( data ){
});
}, 5000)
Try this..
$now = time();
$less_ten = (intval($now) - 10);
echo 'Now:'. date("Y-m-d H:i:s", $now);
echo 'Less:'. date("Y-m-d H:i:s", $less_ten)."<br>";
I'm using date('H', strtotime($_GET['h'].' +1 hour')) at the moment ($_GET['h'] contains the hour I'm getting from the URL, i.e. 20 as in 20:00) but it only prints 01 when it should print 21. I want to get this hour and add one hour to it so 20 will be 21 and so on.
What am I doing wrong here?
Something like this should work:
$time = DateTime::createFromFormat('H:i', '20:00');
$time->modify('+1 hour');
echo $time->format('H:i');
See it in action
You can add seconds to the timestamp to do this:
date('H',mktime($_GET['h']) + 60 * 60)
Since the timestamp must be in seconds, the first 60 * 60 gets the hour in seconds. The second one adds an hour's worth of seconds to the timestamp.
I am currently trying to get a countdown clock using a unix timestamp value (remaining seconds) to H:M:S format, in order to sync my client side timers.
The value that I need to change to H:M:S has already been calculated as the time remaining in the countdown.
Let
$remaining_time
be our value of remaining seconds in the countdown.
Currently, here is what I have:
$H = floor($remaining_time / 3600);
$M = floor(($remaining_time - ($H*3600)) / 60);
$S = floor($remaining_time - ($H*3600 - ($M*60)));
I believe the hours/minutes is pretty close... but the seconds seems to be off. For example, I am getting results like this
$remaining_time = 4135;
Result: Time Remaining at price formatted: H:1 M:8 S:1015
Any information is appreciated - again, I need the remaining seconds in hours, minutes, and seconds.
Use gmdate, example:
<?php
$remaining_time = 4135;
echo "Time Remaining at price formatted: ".gmdate("\H:H \M:i \S:s",4135);
//Result: Time Remaining at price formatted: H:01 M:08 S:55
?>