For some reason, Javascript I am trying to execute with php is not working.

Below is my code.

<script type="text/javascript">
function GetIst() { 
var d = new Date()
var gmtHours = -d.getTimezoneOffset();
document.write(+ gmtHours);
}
</script>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("mysql2", $con);
$reminder ="<script language=javascript>GetIst();</script>";
$currentdate = date("Y-m-d");  
$res = mysql_query("SELECT * FROM schedule WHERE sch_date >= '$currentdate' ORDER BY timestmp ASC limit 20");
while ( $row = mysql_fetch_array($res) ) {
   echo '<br />'.date('H:i', strtotime("+$reminder minutes",strtotime($row["sch_time"]))); 
}

?>

For some reason below code does work.

<?php 
$time_current = "<script language=javascript>GetIst();</script>"; 
echo "". $time_current; 
?>

This below code is working at my end.

<script type="text/javascript">
function GetIst() { 
var d = new Date()
var gmtHours = -d.getTimezoneOffset();
document.write(+ gmtHours);
}
</script>
<?
	$reminder ="<script language=javascript>GetIst();</script>";
	echo $reminder;
?>

Bcz your code is merging of js and php.
Just refer this :
But whenever a php page is loaded all code inside php tag is executed at server side and when page comes at browser js will be executed in client side.

So when we have to merge JS and PHP then take in mind above hint.
Tell exact goal of your post with date example so we can help !!!!

This below code is working at my end.
Bcz your code is merging of js and php.
Just refer this :
But whenever a php page is loaded all code inside php tag is executed at server side and when page comes at browser js will be executed in client side.

So when we have to merge JS and PHP then take in mind above hint.
Tell exact goal of your post with date example so we can help !!!!

I have stored time in sch_time field in database. The time is of future date, stored in GMT. Now, when someone visit my page it should also show time as per local viewers zone. So, through javascript I am trying to get the time difference between gmt and local time of visitor.

After getting time, I tried to add difference.

I have make this code.
comment in code will guide you..

Hope it helps...

<script type="text/javascript">
function GetIst(sourcedt)
{ 
	var d = new Date()
	var gmtHours = (-d.getTimezoneOffset()/60);
	var origDate = new Date(sourcedt);
	var futDate = origDate.getTime();
	futDate += (gmtHours*60*60*1000);
	origDate.setTime(futDate);
	//--- below line will generate date string.. you can set your date format 
	//--- this link will help you to create your desire format : http://www.w3schools.com/jsref/jsref_obj_date.asp
	var dt = origDate.getDate()+ "-" +(origDate.getMonth()+1)+ "-" +origDate.getFullYear()+ " " + origDate.getHours()+":"+origDate.getMinutes()+":"+origDate.getSeconds() ;
	document.write(dt);
}
</script>


GMT Date : July 27, 2010 10:00:00
<br />
Convet to local : <?php echo "<script language=javascript>GetIst('July 27, 2010 10:00:00');</script>"; 

// here 'July 27, 2010 10:00:00' will be your dunamic date $row["sch_time"] 
// you have to create this format from $row["sch_time"] to work in JS

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.