Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] wyświetlenie dat mając poczatkowa i końcową, działania na datach
blokern
post 29.10.2020, 18:47:23
Post #1





Grupa: Zarejestrowani
Postów: 107
Pomógł: 0
Dołączył: 27.02.2008

Ostrzeżenie: (0%)
-----


co powinienem zmienic zeby skrypt nie sprawdzal 5 razy tego warunku? z gory dziekuje za podpowiedz

if($pelna_data==$tablica[$zmienna])

  1. $res_date_start = '2020-10-10';
  2. $res_date_end = '2020-10-15';
  3.  
  4. $liczba_dni = ((strtotime($res_date_end))-(strtotime($res_date_start)) )/ (60*60*24);
  5.  
  6. $tablica = array();
  7.  
  8. for ($number_day = 0; $number_day <= $liczba_dni; $number_day++) {
  9.  
  10. $data_do_sprawdzenia = date('Y-m-d', strtotime( $res_date_start . " +$number_day day"));
  11.  
  12. $tablica[] = $data_do_sprawdzenia;
  13. }
  14.  
  15. print_r($tablica);
  16.  
  17. function days_in_month($month, $year)
  18. {
  19. return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
  20. }
  21.  
  22. echo '<table>';
  23. echo '<tr><td></td>';
  24. for ($number = 1; $number <= 31; $number++) {
  25. echo '<td>'.$number.'</td>';
  26. }
  27. echo '</tr>';
  28.  
  29. for ($number = 1; $number <= 12; $number++) {
  30. echo '<tr><td>'.$number.'</td>';
  31. for ($day = 1; $day <= days_in_month($number,2020); $day++) {
  32.  
  33. $pelna_data = '2020-'.$number.'-'.$day;
  34. $zmienna = '0';
  35. while($zmienna < $liczba_dni+1) // warunek kontynuacji pętli
  36. {
  37. if( isset($tablica[$zmienna]) ){
  38. if($pelna_data==$tablica[$zmienna]){
  39. echo '<td style="background: #ff6600;">'.$day.'</td>';
  40. }else{
  41. echo '<td style="background: #ccc;">'.$day.'</td>';
  42. }
  43. }
  44. $zmienna++;
  45. }
  46. }
  47. echo '</tr>';
  48. }
  49. echo '</table>';




Ten post edytował blokern 29.10.2020, 19:04:25


--------------------
www.Opiekuj.pl
Go to the top of the page
+Quote Post
gitbejbe
post 29.10.2020, 20:37:25
Post #2





Grupa: Zarejestrowani
Postów: 515
Pomógł: 63
Dołączył: 27.08.2012

Ostrzeżenie: (0%)
-----


  1. function date_range($first, $last, $step = '+1 day', $output_format = 'd/m/Y' ) {
  2.  
  3. $dates = array();
  4. $current = strtotime($first);
  5. $last = strtotime($last);
  6.  
  7. while( $current <= $last ) {
  8.  
  9. $dates[] = date($output_format, $current);
  10. $current = strtotime($step, $current);
  11. }
  12.  
  13. return $dates;
  14. }
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.03.2024 - 11:47