Jump to content

[SOLVED] Week Ending Dates


tekrscom

Recommended Posts

Hi, could someone please give me a boost in the right direction with this...

 

When a user logs on, he should have a drop down selection box of week ending dates that would include any week ending dates that he hasn’t completed time for, only going back as far to a specified date and then also the current week he is within and up to 1 week forward. The week ending dates should always be on a Sunday.

 

The table I have is as follows;

 

CREATE TABLE `techs_pay_weeks` (

  `tech_pay_week_id` int(11) NOT NULL auto_increment,

  `tech_pay_week_ending_date` date NOT NULL default '0000-00-00',

  `tech_id` int(11) NOT NULL default '0',

  `tech_pay_week_hours` float NOT NULL default '0',

  `tech_pay_week_amt` float NOT NULL default '0',

  `tech_pay_week_approved` tinyint(4) NOT NULL default '0',

  PRIMARY KEY  (`tech_pay_week_id`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

 

The tech_id is held as a $_SESSION[userid] when he logs in.

 

I understand how to advance a date, but not from a dynamic date that should always fall on a Sunday, and a current Sunday at that.

Link to comment
https://forums.phpfreaks.com/topic/54880-solved-week-ending-dates/
Share on other sites

try this

<?php
$last = strtotime("last Sunday");

$sunday = date("D M j Y", $last);

echo $sunday; // as of today (sat Jun 9 2007) prints out Sun Jun 3 2007
echo "<BR>";

for ($i = 1; $i <52 ;$i++)
{
$sunarray[] = date("D M j Y", $last);
$last = strtotime("+1 Week", $last);
}

print_r($sunarray); //prints out all the Sundays for the next year
?>

I took that code and attempted to make it work for what I need, but instead of it filling my drop down box with the date, e.g. Sun Jun 3 2007 & Sun Jun 10 2007 , it filled it with 0 & 1 ... Here's what I did with the code...

 

<?php
$last = strtotime("last Sunday");

$sunday = date("D M j Y", $last);


for ($i = 1; $i < 3 ;$i++)
{
$sunarray[] = date("D M j Y", $last);
$last = strtotime("+1 Week", $last);
}

echo '<select name="week_ending_date">';
foreach($sunarray as $sunarray=>$last)
{
echo '<option value="', $sunarray, '">', $sunarray, '</option>';
}
echo '</select>';

?>

 

I know I'm doing something wrong with the the array and the loop, I just don't know what...

yes indeed, you have put the variable $last in there when it is not required, try this

<?php
$last = strtotime("last Sunday"); // I have removed the $sunday line because it is not needed for your code

for ($i = 1; $i < 3 ;$i++)
{
$sunarray[] = date("D M j Y", $last);
$last = strtotime("+1 Week", $last);
}

echo '<select name="week_ending_date">';
foreach($sunarray as $var)
{
echo '<option value="', $var, '">', $var, '</option>';
}
echo '</select>';

?>

 

because you put the key value in the foreach loop it did what you asked and gave you the key number.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.