Jump to content

[SOLVED] strtotime problem


mhaey

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
Share on other sites

uhmm.. i know im a noob.. but i really need an answer why the year is 2001..  ??? it might not be the strtotime.. when i check my date("mdy",strtotime("now")); it returns the right date... what should be the problem here...  ???

Link to comment
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.

Link to comment
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.

 

thank you so much.. ^__^

Link to comment
Share on other sites

uhmm.. i notice that when the sdate was 01/01/2007 and edate was 01/08/2007.. the output was

 

01/01/2007

01/02/2007

01/03/2007

01/04/2007

01/05/2007

01/06/2007

01/07/2007

 

what about the enddate..

 

never mind.. i figure it out already.. ^___^

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.