logo
down
shadow

return difference of hours of 2 different days


return difference of hours of 2 different days

By : P He
Date : October 16 2020, 03:08 PM
hop of those help? You would need to compare the dates before getting the difference. Moment has built in functions for comparing dates: https://momentjs.com/docs/#/query/is-before/
You can also skip the conversion to milliseconds and then hours. diff accepts a second argument for the value you want it returned in. https://momentjs.com/docs/#/displaying/difference/
code :
var time1 = "1970-01-01 20:00:00";
var time2 = "1970-01-02 01:00:00";
var timeOne = moment(time1);
var timeTwo = moment(time2);
var hourDiff = (timeOne.isBefore(timeTwo)) ?
    timeTwo.diff(timeOne, "hours") :
    timeOne.diff(timeTwo, "hours");
var timeOfHourExtra = hourDiff.toString() + ':00:00';
// 5:00:00


Share : facebook icon twitter icon
how to return duplicate rows if date difference is equal or more than 4 days or 96 hours

how to return duplicate rows if date difference is equal or more than 4 days or 96 hours


By : user5244285
Date : March 29 2020, 07:55 AM
This might help you The below query returns the expected result, added the inline comments:
code :
-- Simply grouping each ID and get unique row with minimum date
SELECT MIN(SDATE) [SDate], ID
FROM tt
GROUP BY ID

UNION 

-- Get the row with each ID's difference is more than 96 hours
SELECT D.MaxDate  [SDate], D.ID
FROM (
    SELECT MIN(SDATE) [MinDate], MAX(SDATE) [MaxDate], ID
    FROM tt
    GROUP BY ID
) D
WHERE DATEDIFF(HH, D.MinDate, D.MaxDate) >= 96
SQL difference between two days in hours per day

SQL difference between two days in hours per day


By : Ronak
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You can use generate_series to generate all the datetimes with an interval of 1 hour between the start and end dates. Then you can group by the date part to get the number of hours worked each day.
code :
select dt_time::date,count(*) as hours_by_day
from (select generate_series('2017-02-02 11:00:00','2017-02-13 15:00:00',interval '1 hour') as dt_time
     ) x
group by dt_time::date
order by 1
PHP: Return all 24 hours format hours between two days as string

PHP: Return all 24 hours format hours between two days as string


By : user1586497
Date : March 29 2020, 07:55 AM
help you fix your problem While suresh answer is correct in most cases it doesn't cover all of them.
When timezones, daylight saving time comes into play things get messy.
code :
$from = new DateTime("2018-01-10 10:00:00 UTC");
$to = new DateTime("2018-01-10 16:00:00 UTC");
$interval = new DateInterval("PT1H");

for ($now = clone $from; $now < $to; $now->add($interval)) {
    echo $now->format("Y-m-d H:i:s e  -->  H:i A") . "\n";
}
2018-01-10 10:00:00 UTC  -->  10:00 AM
2018-01-10 11:00:00 UTC  -->  11:00 AM
2018-01-10 12:00:00 UTC  -->  12:00 PM
2018-01-10 13:00:00 UTC  -->  13:00 PM
2018-01-10 14:00:00 UTC  -->  14:00 PM
2018-01-10 15:00:00 UTC  -->  15:00 PM
$from = new DateTime("2018-03-24 20:00:00 Europe/Warsaw");
$to = new DateTime("2018-03-25 06:00:00 Europe/Warsaw");
$interval = new DateInterval("PT1H");

for ($now = clone $from; $now < $to; $now->add($interval)) {
    echo $now->format("Y-m-d H:i:s e  -->  H:i A") . "\n";
}
2018-03-24 20:00:00 Europe/Warsaw  -->  20:00 PM
2018-03-24 21:00:00 Europe/Warsaw  -->  21:00 PM
2018-03-24 22:00:00 Europe/Warsaw  -->  22:00 PM
2018-03-24 23:00:00 Europe/Warsaw  -->  23:00 PM
2018-03-25 00:00:00 Europe/Warsaw  -->  00:00 AM
2018-03-25 01:00:00 Europe/Warsaw  -->  01:00 AM
2018-03-25 03:00:00 Europe/Warsaw  -->  03:00 AM
2018-03-25 04:00:00 Europe/Warsaw  -->  04:00 AM
2018-03-25 05:00:00 Europe/Warsaw  -->  05:00 AM
What is the difference between 2 days and 48 hours in php

What is the difference between 2 days and 48 hours in php


By : Karl G.
Date : March 29 2020, 07:55 AM
hope this fix your issue ,
Are they same or different
code :
$twoDays = new DateInterval('P2D');
$fortyEightHours = new DateInterval('PT48H');

$ref = new DateTimeImmutable('2019-04-07T01:00:00',
        new DateTimeZone('Australia/Melbourne'));

echo 'Reference:     ', $ref->format('r'), PHP_EOL;
echo 'Plus 2 days:   ', $ref->add($twoDays)->format('r'), PHP_EOL;
echo 'Plus 48 hours: ', $ref->add($fortyEightHours)->format('r'), PHP_EOL;
Reference:     Sun, 07 Apr 2019 01:00:00 +1100
Plus 2 days:   Tue, 09 Apr 2019 01:00:00 +1000
Plus 48 hours: Tue, 09 Apr 2019 00:00:00 +1000
Calculate the hours minutes and days of difference between two date and hours

Calculate the hours minutes and days of difference between two date and hours


By : user3542296
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have a PHP and MySQL code that should calculate the hours minutes and days of difference between two date and hours. It works well, just adding 20 hours and 20 minutes more than normal. And I remove the DATE part and put the date and time manually, it works fine. , A simple example like this would do the job :
code :
$mydatetime = new DateTime();
$datefromdb = new DateTime('2018-03-05 10:10:00');
$interval = $mydatetime->diff($datefromdb);
$date_count = $interval->format('%y years %m months %a days %h hours %i minutes %s seconds');
echo $date_count;
$fecha = $row["fecha"];
$data= $row["hora"];
$start = strtotime("$fecha $data"); 


$currentDate = date("Y-m-d");
$currentTime = date("H:i:s");
$currentDate =  date("Y-m-d H:i:s", strtotime($currentDate .$currentTime));

$end = strtotime("$currentDate"); 



$totaltime = ($end - $start)  ; 

$hours = intval($totaltime / 3600);   
$seconds_remain = ($totaltime - ($hours * 3600)); 

$minutes = intval($seconds_remain / 60);   
$seconds = ($seconds_remain - ($minutes * 60));
$statusfichaje= $row["status"];
if ($statusfichaje == $start){echo '<td>Trabajando'.$hours.':'.$minutes.':'.$seconds.' </td>';}else{echo '<td>'. $row["status"] .'</td>';}
Related Posts Related Posts :
  • What's the proper way to pass dependencies between components in React?
  • Card Number Regex and caret/cursor position (javascript)
  • Jquery loop append contents
  • Error in decode json code
  • How to click in GreaseMonkey
  • Local vs. global variables in javascript
  • chrome 53 not catching unhandled rejected promises
  • Regular expression not progressing after first match
  • get variable inside the function
  • setup angular js application index.html page to include only singe controller
  • How to draw a pie with logarithmic scale in HighCharts?
  • show div content when a link is clicked
  • React and FLUX - Where would I implement server routines in my web app?
  • Update div on typing base on data attribute
  • CSS: Div resizing depending on original size
  • Default color for webgl 3D scene
  • Autohide a div if any buttons are pressed
  • get value from table sapui5 xml
  • Is this code from w3school correct?
  • Why does this array copying not work as expected?
  • Week picker that fills in start and end date into two inputs
  • Right click menu on svg
  • Removing a portion of text
  • how to instantiate an es6 class after it's been bundled into a function by webpack
  • Use html link to open javascript modal
  • Check if text input is not empty
  • How do I validate start time and end time using select
  • Form submit is not prevented when trying to integrate VueJS with SemanticUI
  • Should i install node and npm if i am not a node programme but i want to use bower?
  • ng-view does not get the data from href?
  • THREE.js - Graphical Glitch with an imported model
  • ViewModel current state to JSON
  • How to stop multiple row highlighting
  • Custom input element in native form
  • Angular service unable to execute function
  • Enable/disable input field depending on array length in Angular 1.5
  • Angular Load Json Error
  • how is dart compiled into javascript?
  • How to create dynamic radio button using javascript
  • Nodejs/Express - Error: Can't set headers after they are sent
  • javascript remove all elements :Uncaught SyntaxError: Unexpected identifier
  • onchange event of text box not working if i change text value dynamically
  • Determine the position of the view port scroll bar
  • Uploading file on site from DropBox
  • How to change the legends from vertical view to horizontal view?
  • Recursive function to create a tree
  • How to apply my class from css to checkbox?
  • If statement on every case within switch
  • checking JSON Data contains media or not..?
  • Binding a list with deviders to the DOM AngularJS
  • Extra blank space is including in dynamic dropdown in angularjs
  • How do I only update one value of my reducer in Redux?
  • Display embedded PDF in Internet Explorer 11 from binary string or base64
  • Convert String to nested array of characters
  • Angular 2 HTTP get handling 404 error
  • Single page with multiple states controlled by URL
  • call prototype method inside callback function of prototype method
  • How To Put Values Dynamically
  • I have custom google map multiple markers.when i am using reverse geolocation for multiple marker
  • Use casperjs to get all links from a page
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com