Hey, wondering if anyone can help me here.
After a function that will loop through a given year, print every date in that year (yyyy/mm/dd) to the screen with correct days in month (cattering for leap years too).
i.e.
2006
01/01/2006
02/01/2006
..
..
31/12/2006
with leap years showing the 29th day in feb.
Any ideas where to loop would be very helpful.
Thanks!
Date looping
Moderator: General Moderators
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
You're asking how to loop it?
Just get the first day of the year
then increment it by one day in a loop
and print out the day as you want
ex:
Or did you ask about something else?
Just get the first day of the year
Code: Select all
$time = mktime(12,0,0,1,1,2006);Code: Select all
$time += 24*3600;Code: Select all
echo date("r", $time);Code: Select all
$year = 2006;
$time = mktime(12,0,0,1,1,$year);
while (date("Y", $time) == $year) {
echo date("r", $time)."<br />\r\n";
$time += 24*3600;
}-
b00ker_b0y
- Forum Newbie
- Posts: 10
- Joined: Thu Jun 22, 2006 7:16 am
Looping
Yeah, sorry quite new to all this.
I just wanted to loop through every date in a given year. But i cant loop through 365 times as leap years I will need to loop through 366.
Could be confusing myself tho.
I just wanted to loop through every date in a given year. But i cant loop through 365 times as leap years I will need to loop through 366.
Could be confusing myself tho.
-
b00ker_b0y
- Forum Newbie
- Posts: 10
- Joined: Thu Jun 22, 2006 7:16 am
Thanks
Thanks, just tried your code. But how would i get it in the following formate only yyyy-mm-dd? not familiar with this mktime function.
-
jamiel
- Forum Contributor
- Posts: 276
- Joined: Wed Feb 22, 2006 5:17 am
- Location: London, United Kingdom
Look at http://php.net/date
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
It's not in the mktime() function but in date() (check jamiels link).
should do the trick.
Code: Select all
echo date("Y-m-d", $time);-
b00ker_b0y
- Forum Newbie
- Posts: 10
- Joined: Thu Jun 22, 2006 7:16 am
thanks
cheers people. thanks for the help.