Generate days of the month

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
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Generate days of the month

Post by xionhack »

Hello. I want to generate the initial of the day of all the days of a chosen month. Meaning, if I choose this month it will give me:

TFSSMTWTFSSMTWTFSSMTWTFSSMTWTF

Is that clear? Can anybody help me? thanks!
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Generate days of the month

Post by mikosiko »

Is that clear? Can anybody help me?
sure... why not?.... her you go :
http://us.php.net/manual/en/ref.datetime.php
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Generate days of the month

Post by xionhack »

Honestly, I tried. The only reason why I posted that here is because I havent found the way how to figure it out
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Generate days of the month

Post by pickle »

Generate a timestamp for the first day of the month. Then, using that timestamp, find the day of the week & get the first character. Increment your timestamp by 1 day using strtotime() & repeat. Continue until your timestamp is greater than the timestamp of the last day of the month.

There are probably more efficient ways of doing this with a for loop & arrays, but this'll at least get you started.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply