date problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mhaey
Forum Newbie
Posts: 1
Joined: Mon Oct 01, 2007 1:28 am

date problem

Post by mhaey »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


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

Code: Select all

<?
$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 '
'.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.. is there any problem about strtotime or the mktime function?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]3.[/b] Do not make multiple, identical posts. This is viewed as spam and will be deleted.[/quote]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Take a closer look at
date(mktime(0, 0, 0, date($startDate) , date($startDate)+$wd, date($startDate)))
What's the first parameter of date(9 supposed to be?
Post Reply