Jump to content

Recommended Posts

hi.. im having some problem regarding strtotime and date function.. i want to find the difference between two dates using strtotime.. and then use the difference in loop to determine the dates between the two given dates... but instead of year 2007.. the output year is 2001.. how come? here's my code..

 

<?

$startDate="01/01/2007";

$endDate="01/08/2007";

 

$days = (strtotime($endDate) - strtotime($startDate)) / 86400 +1;

 

for ($wd = 0; $wd < $days; $wd++)

{

  $weekdays = date(mktime(0, 0, 0, date($startDate)  , date($startDate)+$wd, date($startDate)));

  echo '<br>'.date("d-m-Y",$weekdays);

}

?>

 

and here is my output...

 

01/01/2007

01/08/2007

 

01-01-2001

02-01-2001

03-01-2001

04-01-2001

05-01-2001

06-01-2001

07-01-2001

08-01-2001

 

help.. anyone..

Link to comment
https://forums.phpfreaks.com/topic/71323-solved-strtotime-problem/
Share on other sites

<?php
$startDate="01/01/2007";
$endDate="01/08/2007";
$startD = strtotime($startDate);
$endD = strtotime($endDate);
$diffSeconds = $endD - $startD;
$days = ($diffSeconds / 86400);
for ($wd = 1; $wd < $days; $wd++)
{
	$weekdays = ($startD + 86400*($wd));
	echo date("d-m-Y",$weekdays) . "<br />";
}
?>

 

If you want the difference to include the first day, then change the for loop to $wd = 0.

<?php
$startDate="01/01/2007";
$endDate="01/08/2007";
$startD = strtotime($startDate);
$endD = strtotime($endDate);
$diffSeconds = $endD - $startD;
$days = ($diffSeconds / 86400);
for ($wd = 1; $wd < $days; $wd++)
{
	$weekdays = ($startD + 86400*($wd));
	echo date("d-m-Y",$weekdays) . "<br />";
}
?>

 

If you want the difference to include the first day, then change the for loop to $wd = 0.

 

thank you so much.. ^__^

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.