Connecting Tech Pros Worldwide Forums | Help | Site Map

Not getting current date in calendar using strtotime

cassbiz's Avatar
Familiar Sight
 
Join Date: Oct 2006
Location: Florida
Posts: 204
#1: Jan 15 '07
I am using strtotime and I have read up on some examples and am getting the wrong output, it jumps by several days instead of one day at a time.

Ultimately what I am trying to accomplish is to set up an arrival time and a departure time for the script. This is using AJAX (which I am such a newbee @) from my earlier post http://www.thescripts.com/forum/thre...3131-1-10.html
Any help is greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. $output = '';
  4.  
  5. if($_GET[month] == '' && $$_GET[year] == '') {
  6.         $time = time();
  7.         $month = date('n',$time);
  8.     $year = date('Y',$time);
  9. }
  10.  
  11. $date = getdate(mktime(0,0,0,$month,1,$year));
  12. $today = getdate();
  13. $hours = $today[hours];
  14. $mins = $today[minutes];
  15. $secs = $today[seconds];
  16.  
  17. if(strlen($hours)<2) $hours="0".$hours;
  18. if(strlen($mins)<2) $mins="0".$mins;
  19. if(strlen($secs)<2) $secs="0".$secs;
  20.  
  21. $days=date("t",mktime(0,0,0,$month,1,$year));
  22. $start = $date[wday]+1;
  23. $name = $date[month];
  24. $year2 = $date[year];
  25. $offset = $days + $start - 1;
  26.  
  27. if($month==12) {
  28.         $next=1;
  29.         $nexty=$year + 1;
  30. } else {
  31.         $next=$month + 1;
  32.         $nexty=$year;
  33. }
  34.  
  35. if($month==1) {
  36.         $prev=12;
  37.         $prevy=$year - 1;
  38. } else {
  39.         $prev=$month - 1;
  40.         $prevy=$year;
  41. }
  42.  
  43. if($offset <= 28) $weeks=28;
  44. elseif($offset > 35) $weeks = 42;
  45. else $weeks = 35;
  46.  
  47. $output = "<table class='daytable' cellpadding='3' cellspacing='1' align='center'>
  48. <tr>
  49.         <td colspan='7'>
  50.                 <table border='0' width='100%'>
  51.                 <tr>
  52.                         <td valign='middle'>
  53.                                 <a href='javascript:navigate($prev,$prevy)'><img src='left.gif' border='0'></a><a href='javascript:navigate(\"\",\"\")'><img src='center.gif' hspace='3' border='0'></a><a href='javascript:navigate($next,$nexty)'><img src='right.gif' border='0'></a>
  54.                         </td>
  55.                         <td align='right'>
  56.                                 <div id='heading'>$name $year2</div>
  57.                         </td>
  58.                 </tr>
  59.                 </table>
  60.         </td>
  61. </tr>
  62. <tr>
  63.         <td class='dayhead'>Sun</td>
  64.         <td class='dayhead'>Mon</td>
  65.         <td class='dayhead'>Tue</td>
  66.         <td class='dayhead'>Wed</td>
  67.         <td class='dayhead'>Thu</td>
  68.         <td class='dayhead'>Fri</td>
  69.         <td class='dayhead'>Sat</td>
  70. </tr>";
  71.  
  72. $col=1;
  73. $cur=1;
  74. $next=0;
  75.  
  76. for($i=1;$i<=$weeks;$i++) {
  77.         if($next==3) $next=0;
  78.         if($col==1) $output.="<tr class='dayrow'>";
  79.  
  80.         $output.="<td valign='top' class='days' onMouseOver=\"this.style.backgroundColor='#EEEEEE'\" onMouseOut=\"this.style.backgroundColor='#FFFFFF'\">";
  81.  
  82.         if($i <= ($days+($start-1)) && $i >= $start) {
  83.                 $output.="<div";
  84.                 if(($cur==$today[mday]) && ($name==$today[month])) $output.=" style='color:#FF0000'";
  85.         $day=strtotime("$cur/$month/$year 12:00:00");
  86.         $arr = $day;
  87.         $output.="><a href=\"ajax_calendar.php?arr_date=$arr\" ><b>$cur</b></a>";
  88.  
  89.         $output.="</div></td>";
  90.         $cur++;
  91.         $col++;
  92.         } else {
  93.                 $output.="&nbsp;</td>";
  94.                 $col++;
  95.         }
  96.  
  97.     if($col==8) {
  98.             $output.="</tr>";
  99.             $col=1;
  100.     }
  101. }
  102.  
  103. $output.="</table>";
  104.  
  105. echo $output;
  106.  
  107. ?>
  108.  
  109.  

Newbie
 
Join Date: Jan 2007
Location: Netherlands
Posts: 12
#2: Jan 17 '07

re: Not getting current date in calendar using strtotime


you might just wanna use date()?
Newbie
 
Join Date: Nov 2006
Posts: 6
#3: Jan 18 '07

re: Not getting current date in calendar using strtotime


strtotime() function return timestamp.So you first take current timestamp using
strtotime then convert it using date function.
<?php
$now=strtotime("now()");
echo $curdate=date("d/m/Y",$now);
?>
Reply