Guest User

Untitled

a guest
Jan 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. 1=2012-10-07
  2. 1=2012-10-08
  3. 1=2012-10-09
  4. 1=2012-10-10
  5. 2=2012-10-07
  6. 2=2012-10-08
  7. 2=2012-10-09
  8. 2=2012-10-10
  9. 3=2012-10-05
  10. 3=2012-10-06
  11. 3=2012-10-08
  12. 3=2012-10-09
  13. 3=2012-10-10
  14.  
  15. 1 available from 7-10 October 2012 //I know this line need to use date("F Y",strtotime());
  16. 2 available from 7-10 October 2012
  17. 3 available from 5-10 October 2012
  18.  
  19. $dates = array('2000-10-02', '2000-10-01', '2000-10-03');
  20. sort($dates);
  21.  
  22. // prints "1-3 October 2000"
  23. echo date('j', strtotime(current($dates))) . '-'
  24. . date('j', strtotime(end($dates))) . ' '
  25. . date('F Y', strtotime(current($dates)));
  26.  
  27. $dates = array(
  28. array(1, "2012-10-07"),
  29. array(1, "2012-10-08"),
  30. array(1, "2012-10-09"),
  31. array(1, "2012-10-10"),
  32. array(2, "2012-10-07"),
  33. array(2, "2012-10-08"),
  34. array(2, "2012-10-09"),
  35. array(2, "2012-10-10"),
  36. array(3, "2012-10-05"),
  37. array(3, "2012-10-06"),
  38. array(3, "2012-10-08"),
  39. array(3, "2012-10-09"),
  40. array(3, "2012-10-10")
  41. );
  42. $info = array();
  43. foreach($dates as $roominfo) {
  44. $time = strtotime($roominfo[1]);
  45. $room = $roominfo[0];
  46. if(!array_key_exists($roominfo[0], $info))
  47. $info[$room] = array($time, $time);
  48. if($time<$info[$room][0])
  49. $info[$room][0] = $time;
  50. if($time>$info[$room][1])
  51. $info[$room][1] = $time;
  52. }
  53.  
  54. foreach($info as $roomId => $roomRange) {
  55. echo $roomId.' available from '.
  56. date('d', $roomRange[0]).' - '.
  57. date('d F Y', $roomRange[1]).' <br/>';
  58. }
  59.  
  60. 1 available from 07 - 10 October 2012
  61. 2 available from 07 - 10 October 2012
  62. 3 available from 05 - 10 October 2012
  63.  
  64. <?php
  65. $dates = array('2012-10-07','2012-10-10','2012-10-01');
  66. $stimes = array_map('strtotime',$dates);
  67.  
  68. var_dump($dates);
  69. var_dump($stimes);
  70.  
  71. echo date('F j, Y', min($stimes));
  72. echo "<br />n";
  73. echo date('F j, Y', max($stimes));
Add Comment
Please, Sign In to add comment