www.webdeveloper.com
Results 1 to 4 of 4

Thread: using php date function with javascript date function

  1. #1
    Join Date
    Nov 2010
    Posts
    5

    using php date function with javascript date function

    Hi Everyone,

    I m having trouble with using php and javascript date functions together.
    I got a jquery based timetable script somewhere from internet and modified it according to my requirements. You can see the timetable live at http://reviewturn.com/work-shop/mattsmarttraining/
    .
    Now how the timetable works? It takes input from php mysql and creates icons on relevant dates. Input includes title, desc, date.
    It working fine expect the date problem. Now if the input date is 2011-03-16, the icon will appear on 2011-04-16. In other words, it puts the icon on the same date of next month. This is the issue.

    My code:

    Code:
       <script type='text/javascript'>
    
    	var eventData = {
    		events : [
    		<?php do { 
    		if($row_classes['class_type'] == "Circuit training"){
    			$classtype = "c";
    			}
    			if($row_classes['class_type'] == "Boxing"){
    			$classtype = "b";
    			}
    			if($row_classes['class_type'] == "Running"){
    			$classtype = "r";
    			}
    			$id = $row_classes['class_id'];
    			$date = $row_classes['cdate'];
    			//echo $date;
    			//$date = strtotime(date("Y,m,d", strtotime($date)). "-1 month");
    			$date = date('Y,m,d',strtotime($date));
    			//echo $date;
    			
    			$ctype = $row_classes['class_type'];
    			$time = $row_classes['ctime'];
    			$trainer = $row_classes['name'];
    			$ocation = $row_classes['loc_name'];
    			$places = $row_classes['Places'];
    			
    			if( !empty($prevdate) and $prevdate == $date){	
    			$c++;
    			if ($c == 1){ $stime = 00; $etime = 06;}
    			if ($c == 2){ $stime = 06; $etime = 12;}
    			if ($c == 3){ $stime = 12; $etime = 18;}
    			if ($c == 4){ $stime = 18; $etime = 24;}
    			
    			}else{				
    			$c == 1;
    				$stime = 00; $etime = 06;
    				}
    			//$stime = 00; $etime = 06;
    			$prevdate = $date;
    			//echo $ocation;
    
    		?>	
    
    		   {"id":'<?php echo $id; ?>', "start": new Date(<?php echo $date; ?>,<?php echo $stime; ?>), "end": new Date(<?php echo $date; ?>,<?php echo $etime; ?>),"title":'<h4><?php echo $ctype; ?> <strong><?php echo $time; ?></strong></h4><p><?php echo $ocation; ?></p><p>Trainer: <?php echo $trainer; ?> </p><p>Places: <?php echo $places; ?> </p><p><a href="reserve.php?classid=<?php echo $id; ?>" class="fly">Click to book now.</a></p>', "classtype":'<?php echo $classtype; ?>'},
    		   <?php } while ($row_classes = mysql_fetch_assoc($classes)); 
    		
    		?>
    		  ]
    	};
    	   
    	$(document).ready(function() {
    
    		$('#calendar').weekCalendar({
    			date: new Date(),
    			timeslotsPerHour: 1,
    
    			height: function($calendar){
    				return $(window).height() - $("h1").outerHeight() - $(".description").outerHeight();
    			},
    			eventRender : function(calEvent, $event) {
    				if(calEvent.end.getTime() < new Date().getTime()) {
    					$event.css("backgroundColor", "#fff");
    					$event.find(".time").css({"backgroundColor": "#999", "border":"1px solid #888"});
    				}
    			},
    			data:eventData
    		});
    
    	});
    Let me know if anybody needs more details.
    Please tell me where I m coding wrong. I have spend night on it but still not successful. Please help.

    Thanks in advance
    Nabeel

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Unlike PHP, in JavaScript the counting of the months starts from 0.

  3. #3
    Join Date
    Nov 2010
    Posts
    5
    Yes thats right. But I need a solution for this. Is there is a way I can increase one in javascript date without effecting the monthly date flow. Any function in php or javascript that can me used here.

  4. #4
    Join Date
    Nov 2010
    Posts
    5
    Can any body help me in think issue? :/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles