Jump to content

Date Generator


jvrothjr

Recommended Posts

I am having some issues with getting dates for the days of the week based on one date givin

 

Example:

User enters date for sunday. (Ending pay period) and I wish to get the dates for that week.

Mon - 1-2-2012

Tue - 1-3-2012

Wed - 1-4-2012

Thu - 1-5-2012

Fri - 1-6-2012

Sat - 1-7-2012

Sun - 1-8-2012

 

User would enter 1/8/2012 and the script would get the rest of the dates to enter into the timecard.

 

I have tried both ways below and cant get it to work no mater if i change the user input date i still get the same output.

 

Function getdatepast($dtp,$cnt) {

$undatecon = mktime($dtp);

$undatecon2 = strtotime("-".$cnt." day", $undatecon);

$ddt1 = date('m-d-Y',($undatecon2));

                return $ddt1;

}

 

Function getdatepast($dtp,$cnt) {

$undatecon = mktime($dtp);

$undatecon2 = $undatecon - (86400 * ($cnt));

$ddt1 = date('m-d-Y',($undatecon2));

                return $ddt1;

}

 

Link to comment
Share on other sites

just a rough idea - modify as needed

 

<?PHP
$date = "01/13/2012"; /* your given date in mm/dd/yyyy format */
for($i=1;$i<8;$i++) {
$date2 = date (' m/d/Y' , (strtotime ( '+1 day' , strtotime ( $date ) )) );
echo date (' l' , (strtotime ( '+1 day' , strtotime ( $date ) ) ) ) . " - " . $date2 . "<br/>";
$date = $date2;
}
?>

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.