Jump to content

Using Days (i.e. Mon, Tues) in PHP date query


slaterino

Recommended Posts

Hi,

I am hoping to find an easier way of adding dates for a course for a site I am designing. The course has dates that run each week throughout the year. In one example, there is a course which runs every Monday. However, on a few Mondays through the year it may not run or it may have a slightly different time. I am currently using a simple php form to add dates (there is an option to add a start date and an end date, in case it is more than one day).

 

However, I would like there to be an option so that it could add every Monday between two dates. So for instance there would be a drop-down menu listing Monday-Sunday and two options for Start Date and End Date. It would then create an entry for every specific day specified between those two dates. Does anyone know how I could start creating this. I have included my simple php form script below:

 

  if(isset($_POST['submit']))
  {//begin of if($submit).

      $dates = $_POST['dates'];
      $enddate = $_POST['enddate'];

         $result = mysql_query("INSERT INTO showdates (dates, enddate)
                       VALUES ('$dates','$enddate')",$connect);

          echo "<b>Thank you! Date added Successfully!<br />You'll be redirected to Home Page after (4) Seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
  }//end of if($submit).

else
  {//begin of else

      ?>
<form method="post" action="<?php echo $_SERVER[php_SELF] ?>">
Start Date:<input name="dates" size="40" maxlength="255"><br />Date must be entered in format YYYY-MM-DD
End Date: <input name="enddate" size="40" maxlength="255"><br />Date must be entered in format YYYY-MM-DD
</form>

Link to comment
Share on other sites

one way would be to use PHP to find every monday between the two times, using string to time function, to improve that i would have it loop through the dates going from the start to the end adding one day at a time until it hits the first monday and from there add 7 days at a time, and record the dates for mondays in an array

Link to comment
Share on other sites

 

Was going to do a short project

to show user a simple example, but i stopped sorry, someone can continue if they want.

<?php

$bd=mysql_connect("localhost","username","password");

$sql1="CREATE DATABASE course";
$sql_res1=mysql_query($sql1)or die("create database error".mysql_error());

$sqlc="USE course";
$c=mysql_query($sqlc)or die("use database error".mysql_error());

$sql2="CREATE TABLE users(id int not null auto_increment primary key,
username varchar(50) not null)";

$sql_res2=mysql_query($sql2)or die ("create table users error".mysql_error());

$insert="INSERT INTO users (username)VALUES('redarrow')";
$insert_res=mysql_query($insert)or die("insert error".mysql_error());

$insert="INSERT INTO users (username)VALUES('tim')";
$insert_res=mysql_query($insert)or die("insert error".mysql_error());

$insert="INSERT INTO users (username)VALUES('bill')";
$insert_res=mysql_query($insert)or die("insert error".mysql_error());


$sql3="CREATE TABLE course_dates(id int not null auto_increment primary key,
users_id varchar(50) not null,
date_start int not null,
date_end int not null,
number_of_students int not null)";

$sql_res3=mysql_query($sql3)or die ("create table course_dates error".mysql-error());

//redirect to the page to add dates to the database

if($sql_res3){

header("location: add_date.php");

exit;
}
/*
users dataabse so far.

id 	username
    1 	redarrow
2 	tim
3 	bill

*/


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.