How to find record created in Last quarter using custom query

Hi All,

Please suggest on How to find record created in Last quarter using custom query?

Thanks,

Shreya

Parents
  • If you are looking for a query, mysql has formulas to get the first and last day of the quarter

    SELECT
    MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-2 QUARTER as first_day_of_quarter,
    MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-1 QUARTER - INTERVAL 1 DAY as last_day_of_quarter

    So, for example, to get all the opportunities from last quarter you can use:

    select *
     from opportunities
    WHERE date(date_entered) <=
      MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-1 QUARTER - INTERVAL 1 DAY 
      and date(date_entered) >=
      MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-2 QUARTER 

    FrancescaS

Reply
  • If you are looking for a query, mysql has formulas to get the first and last day of the quarter

    SELECT
    MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-2 QUARTER as first_day_of_quarter,
    MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-1 QUARTER - INTERVAL 1 DAY as last_day_of_quarter

    So, for example, to get all the opportunities from last quarter you can use:

    select *
     from opportunities
    WHERE date(date_entered) <=
      MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-1 QUARTER - INTERVAL 1 DAY 
      and date(date_entered) >=
      MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE())-2 QUARTER 

    FrancescaS

Children
No Data