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
https://forums.phpfreaks.com/topic/254417-date-generator/
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
https://forums.phpfreaks.com/topic/254417-date-generator/#findComment-1304539
Share on other sites

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.