xionhack Posted July 23, 2010 Share Posted July 23, 2010 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! Quote Link to comment Share on other sites More sharing options...
inversesoft123 Posted July 23, 2010 Share Posted July 23, 2010 Yapee! I got the solution <?php $from = date('d-D',strtotime('-1 second',strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')))); $pices = explode('-',$from); if($pices[1] == "Sat") { $p= "SSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFS"; } else if($pices[1] == "Sun") { $p= "SMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTF"; } else if($pices[1] == "Mon") { $p= "MTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWT"; } else if($pices[1] == "Tue") { $p= "TWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTW"; } else if($pices[1] == "Wed") { $p= "WTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMT"; } else if($pices[1] == "Thr") { $p= "TFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSM"; } else if($pices[1] == "Fri") { $p= "SMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSSMTWTFSS"; } else { $p= "LOL! Out of earth LOL! Out of earth LOL! Out of earth LOL! Out of earth LOL! Out of earth"; } echo substr("$p", -$pices[0]); ?> Currently its automatic you can update // strtotime(date('m').'/01/'.date('Y') // this to get magic string of your month. Quote Link to comment Share on other sites More sharing options...
xionhack Posted July 25, 2010 Author Share Posted July 25, 2010 Hi, I was trying this code, but it only works for this month. Its not working for the next months. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 25, 2010 Share Posted July 25, 2010 Could be simplified and it needs some error checking for the args, but here's a quick way: function get_days($month, $year) { for($date=strtotime("$year-$month-1"); date('n', $date) == $month; $date=strtotime("+1 day", $date)) { $days[] = substr(date('D', $date), 0, 1); } return implode($days); } echo get_days('7', '2010'); Quote Link to comment Share on other sites More sharing options...
xionhack Posted July 30, 2010 Author Share Posted July 30, 2010 Thank you! that works! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.