logo
down
shadow

How can I sum/subtract time values from same row


How can I sum/subtract time values from same row

By : user7447747
Date : October 16 2020, 03:08 PM
Does that help Is ARRIVED_AT a calculated value instead of a column? What did you run to get the query results image you posted showing those columns?
The following script does what you expect, so there's something about the structure of the table you're querying that isn't what you expect.
code :
CREATE SCHEMA so46801016;
SET search_path=so46801016;
CREATE TABLE trips (
  person_id serial primary key,
  arrived_at time,
  left_at time
);

INSERT INTO trips (arrived_at, left_at) VALUES
  ('14:30'::time, '19:30'::time)
, ('11:27'::time, '20:00'::time)
;

SELECT
    t.person_id,
    COALESCE(EXTRACT(EPOCH from t.left_at),0) +
    COALESCE(EXTRACT(EPOCH from t.arrived_at),0) AS credit
FROM
    trips t;

DROP SCHEMA so46801016 CASCADE;


Share : facebook icon twitter icon
How to subtract DateTime values and get the Time

How to subtract DateTime values and get the Time


By : Derek
Date : March 29 2020, 07:55 AM
this will help What I basically mean and the exact scenario is. , Subtracting two DateTimes gives you a TimeSpan object:
code :
TimeSpan span = timeEnd - timeStart;
Console.WriteLine("Total work hours: {0}", span.TotalHours);
How to Subtract between two time values using php?

How to Subtract between two time values using php?


By : azies kurniawan
Date : March 29 2020, 07:55 AM
should help you out 00:30:00 is half past midnight, not 30 minutes. You can subtract 30 minutes with the strtotime function by using -30 minutes.
code :
echo date('H:i:s', strtotime('22:00:00 -30 minutes'));
echo date('H:i:s', strtotime('22:00:00 -1 hour -30 minutes'));
echo date('H:i:s', strtotime($lastMealRequested . ' -30 minutes')); 
Trying to subtract moment.js time values

Trying to subtract moment.js time values


By : Max
Date : March 29 2020, 07:55 AM
wish of those help I'm trying to subtract two strings that i have using moment.js, however the end result is NaN. Can someone explain what's going on? Here's the code in question: , You first have to convert your string into a moment object with
code :
moment(myString, "HH:mm:ss");
const elapsedTime = "12:17:34";
const startTime = "12:17:29"; 

const momentElapsedTime = moment(elapsedTime, "HH:mm:ss");
const momentStartTime = moment(startTime, "HH:mm:ss");

const totalTime = momentElapsedTime.valueOf() - momentStartTime.valueOf();

console.log("Total time in ms: " + totalTime);
console.log("Total time in s : " + totalTime/1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
const elapsedTime = "12:17:34";
const startTime = "12:17:29"; 

const momentElapsedTime = moment(elapsedTime, "HH:mm:ss");
const momentStartTime = moment(startTime, "HH:mm:ss");

const totalTime = momentElapsedTime.diff(momentStartTime);

console.log("Total time in ms: " + totalTime);
console.log("Total time in s : " + totalTime/1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
How to subtract two time values?

How to subtract two time values?


By : cedrict
Date : March 29 2020, 07:55 AM
Hope that helps This answer is based on: https://stackoverflow.com/a/4927884/5622596
Imports needed:
code :
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
    String first =  "1:12.203";
    String second = "1:04.009";

    SimpleDateFormat formater = new SimpleDateFormat("mm:ss.SSS");

    try {
        Date dateStart = formater.parse(first);
        Date dateEnd = formater.parse(second);

        long milliSeconds = dateStart.getTime() - dateEnd.getTime(); 

        Date timeDiff = new Date(milliSeconds);

        System.out.println(formater.format(timeDiff));
    } catch (ParseException e) {
        e.printStackTrace();
    }
@Test
public void printDiff() {
    String first = "1:12.203";
    String second = "1:04.009";

    try {
        System.out.println(getTimeDiffString(first, second));
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

private String getTimeDiffString(String first, String second) throws ParseException {
    SimpleDateFormat formater = new SimpleDateFormat("mm:ss.SSS");

    //Get number of milliseconds between times: 
    Date dateStart = formater.parse(first);
    Date dateEnd = formater.parse(second);
    long milliSeconds = dateStart.getTime() - dateEnd.getTime();

    //Convert time difference to mm:ss.SSS string
    Date timeDiff = new Date(milliSeconds);
    return formater.format(timeDiff).toString();

}
How do i get the minutes part when i subtract two time values

How do i get the minutes part when i subtract two time values


By : Alexis
Date : March 29 2020, 07:55 AM
it should still fix some issue It gives wrong value because you are substracting ints. It could even give negative numbers. You should substract the TimeSpan from the DateTime, which gives you another DateTime and use it's Minute property.
Related Posts Related Posts :
  • Raising exception in postgresql
  • postgres index not used
  • Error in PostgreSQL permission denied fo
  • Why do DDL statements hang frequently?
  • inner query in coalesce to set null values
  • Querying Postgres 9.6 JSONB array of objects
  • how can I update the event trigger?
  • Sequence check on Partitions in Postegresql 10
  • Installing phpPgAdmin 5.1 on Ubuntu 16.04 with PostgreSQL 10 not supported
  • sorting within a nested array_agg query
  • How to use PostgreSQL JSONB_SET() to create new deep object element
  • Querying a table with UUID using Ecto.Query gives Ecto.Query.CastError
  • Postgresql index seq scan 100 million rows
  • how to do OR to all the words in full text search instead of AND in postgres
  • Successfully connecting postgreSQL 9.6.5 to pgbouncer 1.7.2
  • Updating integer column with null values in postgres
  • trigger function to refresh remote materialized view on UPDATE
  • No function matches, error is not obvious for anyelement
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com