Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6154255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:14:02+00:00 2026-05-23T20:14:02+00:00

Ok here is some example data and the expected results I would like: 2011-06-26

  • 0

Ok here is some example data and the expected results I would like:

  • 2011-06-26 17:07:38-04 <– Start Date
  • 2011-10-01 00:00:00-04 <– Wanted Date
  • 91 <– Duration in days

  • 2011-06-25 20:08:46-04 <– Start Date

  • 2011-09-01 00:00:00-04 <– Wanted Date
  • 62 <– Duration in days

Here are the conditions:

  • If the day the 1st to the 25th, add two months plus how many days until the next first
  • If the day is the 26th till the end of the month, add three months plus how many days until the next first

Here is what I’m trying and I’m close but this seems to be doing a ton of calculations and I wanted to see if I could simplify it:

CASE
    WHEN (((DATE_TRUNC('month', 
        (date_field + INTERVAL '5 DAYS')) + INTERVAL '2 MONTH') - 
        (date_field + INTERVAL '5 DAYS') >= 62) AND 
        ((DATE_TRUNC('month', (date_field + INTERVAL '5 DAYS')) + 
        INTERVAL '2 MONTH') - (date_field + INTERVAL '5 DAYS') <= 92))
    THEN (DATE_TRUNC('month', 
        (date_field + INTERVAL '5 DAYS')) + INTERVAL '2 MONTH')
    ELSE (DATE_TRUNC('month', 
        (date_field + INTERVAL '5 DAYS')) + INTERVAL '3 MONTH')
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:14:02+00:00Added an answer on May 23, 2026 at 8:14 pm
    select 
        case 
            when extract(day from date_field) <= 25 
            then date_trunc('month', date_field + interval '3 months')
            else date_trunc('month', date_field + interval '4 months')
        end
    from t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
I'm looking for something like break for loops. Here's some example code (using Symfony's
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
Here's some example code: class Obj attr :c, true def == that p '=='
I'm working on a stored proc that executes some dynamic sql. Here's the example
I'm attempting to implement the technique for data validation from Josh Smith's example here:
Im trying to hammer togehter a WYSIWYG-edit in c# following some examples from here
Here is some code I could not get to format properly in markdown, this
Here is some simple Perl to count the number of times a value occurs
Here's some Ruby code: puts %x{ pstree #{$$} } # never forks puts %x{

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.