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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:11:29+00:00 2026-06-13T14:11:29+00:00

Possible Duplicate: Print Y-m-d list of business dates between two dates from MySQL using

  • 0

Possible Duplicate:
Print Y-m-d list of business dates between two dates from MySQL using PHP

I’m new to these kind of PHP programming so bear with me.

I want users to be able to post two dates, a startdate and a enddate and from these dates calculate the business dates (exclude Saturday and Sunday) and insert these to MySQL

For example if I have this form…

<form action='update.php' method='post'>
  <input type='text' name='start_date'>
  <input type='text' name='end_date'>
  <input type='submit' name='submit'>
</form>

update.php

if(isset($_POST['submit'])) {

   $start_date = $_POST['start_date']; //Let's say this is 2012-10-01
   $send_date = $_POST['end_date']; //Let's say this is 2012-10-10

}

Now I would like to loop through the dates and create a MySQL query that would run like this:

INSERT INTO tbl_dates (date_value) VALUES ('2012-10-01');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-02');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-03');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-04');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-05');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-08');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-09');
INSERT INTO tbl_dates (date_value) VALUES ('2012-10-10');

I know this is probably not a good solution but it’s how I need it.

How do I create the loop?

  • 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-13T14:11:30+00:00Added an answer on June 13, 2026 at 2:11 pm
    $startDate = $start_date;
    $endDate = $send_date;
    
    // Convert to UNIX timestamps
    $currentTime = strtotime($startDate);
    $endTime = strtotime($endDate);
    
    // Loop until we reach the last day
    $result = array();
    while ($currentTime <= $endTime) {
      if (date('N', $currentTime) < 6) {
        $result[] = date('Y-m-d', $currentTime);
      }
      $currentTime = strtotime('+1 day', $currentTime);
    }
    
    // start insertion
    foreach($result as $value)
    {
      mysql_query("INSERT INTO tbl_dates (date_value) VALUES '".$value."'");
    }
    

    Source : Print Y-m-d list of business dates between two dates from MySQL using PHP

    Omg! I just realized that it’s a thread started by you. You already have your answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to create comma separated list from array in PHP? I have
Possible Duplicate: How do I randomly select an item from a list using Python?
Possible Duplicate: passing variables from php to javascript I'm dynamically generating a list. I
Possible Duplicate: PHP Built-in Method to Get Array Values Given a List of Keys
Possible Duplicate: Merge two lists in python? How can I prepend list elements into
Possible Duplicate: Correct format specifier to print pointer (address)? When printing a pointer using
Possible Duplicate: How are echo and print different in PHP? As far as I
Possible Duplicate: Print preview ZPL II commands using .NET WinForm before sending it to
Possible Duplicate: Reference: Comparing PHP's print and echo Is there any major and fundamental
Possible Duplicate: Remove items from a list while iterating in Python I want to

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.