skip to Main Content

I using postgres sql.I doing a query to calculate the estimated end date from start date and duration (minutes|hours|days|months|etc). The duration can be in minutes|hours| days|months .
i try to use dateif but it work if we know the start date and end date.

I expecting to get the estimated end date from start date and duration (minutes|hours|days|months|etc)

please help me thank you and have a nice day

2

Answers


  1. I don’t have issue to calculate the date and time. I use ‘interval’ to get result.

    Are you just want to calculate the time? Or is there another issue?

    enter image description here

    Login or Signup to reply.
  2. Many way you can do.

    do
    $$
    declare
    duration timestamp;
    
    begin 
        select timestamp_column + interval '65 minutes' into duration from timestamp_table;
        raise notice 'After duration time : % ', duration;
        
    end;
    $$;
    
    

    This way you read out the interval from another table:

    do
    $$
    declare
    duration timestamp;
    
    begin 
        select timestamp_column + make_interval(mins => ( SELECT your_support_column FROM your_support_table )  into duration from timestamp_table;
        raise notice 'After duration time : % ', duration;
        
    end;
    $$;
    
    

    Support table you can add one column where you just type in the interval, so not need to change in the code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search