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 9161465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:58:22+00:00 2026-06-17T13:58:22+00:00

Possible Duplicate: Grab current first and last day in week in php I am

  • 0

Possible Duplicate:
Grab current first and last day in week in php

I am trying to get the first and last day of the week, month, quarter, and year for a given day.

For instance, for day 2013-01-16, the first and last days would be:

  • Week – It would be 2013-01-13 and 2013-01-19 (assuming Sunday to Saturday)
  • Month – It would be 2013-01-01 and 2013-01-31
  • Quarter – It would be 2013-01-01 and 2013-03-31
  • Year – It would be 2013-01-01 and 2013-12-31

My purpose is to include them in a WHERE myDate BETWEEN 2013-01-13 AND 2013-01-19.

Both a standard MYSQL function solution (but not stored procedure, etc) or PHP solution is acceptable. Thank you


Solution for first and last day of given quarter.

$q=ceil($date->format("n")/3);
$months_start=array('January','April','July','October');
$months_end=array('March','June','September','December');
$m_start=$months_start[$q-1];
$m_end=$months_end[$q-1];
$modifier='first day of '.$m_start.' '.$date->format('Y');
$date->modify($modifier);
echo $modifier.': '.$date->format('Y-m-d').'<br>';
$modifier='last day of '.$m_end.' '.$date->format('Y');
$date->modify($modifier);
echo $modifier.': '.$date->format('Y-m-d').'<br>';
  • 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-06-17T13:58:23+00:00Added an answer on June 17, 2026 at 1:58 pm

    You can use strtotime:

    $date = strtotime('2013-01-16');
    
    // First/last day of week 
    $first = strtotime('last Sunday');
    $last = strtotime('next Saturday');
    

    Or PHP’s native DateTime functionality:

    $date = new DateTime('2013-01-16');
    
    // First/last day of month
    $first = $date->modify('first day of this month');
    $last = $date->modify('last day of this month');
    

    Getting the first/last day of a year might be a little bit more tricky:

    // Get date
    $date = new DateTime('2013-01-16');
    
    // Format to get date
    $year = $date->format('Y');
    
    // Get first day of Jan and last day of Dec
    $first = $date->modify("first day of January $year");
    $last = $date->modify("last day of December $year");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP last day of the month In PHP, I am trying to
Possible Duplicate: Robust, Mature HTML Parser for PHP I'm trying to grab the first
Possible Duplicate: How to parse and process HTML/XML with PHP? I want to grab
Possible Duplicate: How can I get the client's IP address in a PHP webservice?
Possible Duplicate: How to get the id of a row i've just inserted php/mysql
Possible Duplicate: How to parse and process HTML with PHP? I'm trying to use
Possible Duplicate: Find Month difference in php? My server hosts multiple websites, and with
Possible Duplicate: Gmail Contact api How can i get (grab) email contacts by supplying
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Is there a way for MS Access to grab the current Active

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.