-2

Hi frnds...

i m using date time funtion in many ways..but i m not getting indian timings...plz tell me how can i exact indian timings...

i used all the below functions...

php_value date.timezone "Asia/Calcutta"
echo date('d-m-Y H:i:s');

putenv("TZ=Europe/Istanbul");

i need only for a single page..

7
Contributors
28
Replies
30
Views
7 Years
Discussion Span
Last Post by Member 784564
0

Hi frnds...

i m using date time funtion in many ways..but i m not getting indian timings...plz tell me how can i exact indian timings...

i used all the below functions...

i need only for a single page..

You May Use the Below Specified Script for Getting Indian Time in Text Box:

<html>
<body>
<?php
$time_now=mktime(date('h')+5,date('i')+30,date('s'));
$time_now=date('h:i:s A',$time_now);
?>
Time: <input type="text" name="dat1" value="<?php echo $time_now; ?>">
</body>
</html>
0

Hi hemgoyal,

Thanks for ur reply..
here i m getting wrong time...now i m in INDIA..here present time is 11.26 am......but the code displays 04:25:59 PM...

i need indian time zone ..i m using database MYSQL...


plz tell me...

You May Use the Below Specified Script for Getting Indian Time in Text Box:

<html>
<body>
<?php
$time_now=mktime(date('h')+5,date('i')+30,date('s'));
$time_now=date('h:i:s A',$time_now);
?>
Time: <input type="text" name="dat1" value="<?php echo $time_now; ?>">
</body>
</html>
0

using just -

date_default_timezone_set("Asia/Calcutta");
$d = date('Y-m-d H:i:s');

should do actually.what is the problem with this.

0

hey...thank U...

this time i m getting error...

error:

PHP Fatal error: Call to undefined function: date_default_timezone_set()

using just -

date_default_timezone_set("Asia/Calcutta");
$d = date('Y-m-d H:i:s');

should do actually.what is the problem with this.

0

Its clear you are running the older version of PHP and the date_default_timezone_set() is not supported.
check date.timezone in php.ini

0

in my system i m using php version ...5.3.0....

in php.ini..

date.timezone = UTC

Its clear you are running the older version of PHP and the date_default_timezone_set() is not supported.
check date.timezone in php.ini

0

You may Use The Below Specified Code. This Code is Work Fine for Me:

<?PHP
$time_now=mktime(date('h'),date('i'),date('s'));
$time_now=date('h:i:s',$time_now);
$time_zone=date('P'); //This will show Time Zone
echo "The Current Time Zone is $time_zone and Date is: ";
echo gmdate("M d Y"); //Date Creation
echo " Time is: $time_now";
?>
0

hmmm, your PHP version is fine.

Can you not run the code hemgoyal_1990 included in the above post?

Try running the following code to figure out your actual runtime PHP version if it still gives you a function missing error.

<?php echo 'Current PHP version: ' . phpversion(); ?>
-1

hey..
output:

The Current Time Zone is P and Date is: Oct 30 2009 Time is: 12:46:56

but , current time is 01:14 pm;

i want indian timing zone..

You may Use The Below Specified Code. This Code is Work Fine for Me:

<?PHP
$time_now=mktime(date('h'),date('i'),date('s'));
$time_now=date('h:i:s',$time_now);
$time_zone=date('P'); //This will show Time Zone
echo "The Current Time Zone is $time_zone and Date is: ";
echo gmdate("M d Y"); //Date Creation
echo " Time is: $time_now";
?>
0

hey..
output:

The Current Time Zone is P and Date is: Oct 30 2009 Time is: 12:46:56

but , current time is 01:14 pm;

i want indian timing zone..

Dear Friend The Above Code is Work Very Fine for Me.and Give the Below Output:

The Current Time Zone is +05:30 and Date is: Oct 30 2009 Time is: 01:23:56

Please Check Your PHP Version maybe Your PHP Version is Older or Your php.ini File Not Configure Properly for Date & Time Function..

Edited by hemgoyal_1990: n/a

0

Looks like you're just half an hour off. Probably the regional time got updated (Like it happened for us in Sri Lanka). Just find a region that matches your difference from GMT and apply it instead.

This code works and gives the current time for Colombo.

<?php
date_default_timezone_set('Asia/Colombo');
$time_now=mktime(date('h'),date('i'),date('s'));
$time_now=date('h:i:s',$time_now);
$time_zone=date_default_timezone_get(); //This will show Time Zone
echo "The Current Time Zone is $time_zone and Date is: ";
echo gmdate("M d Y"); //Date Creation
echo " Time is: $time_now";
?>

Just pick the timezone you want from here http://www.php.net/manual/en/timezones.asia.php and run the script. It should work.

0

hi ...

Thanks ...

i think the problem with my php version...

can u tell me php version takes from my local system or my server?...i dont know the server php version...

incase if i m using older version of PHP , wat i have to do...

Looks like you're just half an hour off. Probably the regional time got updated (Like it happened for us in Sri Lanka). Just find a region that matches your difference from GMT and apply it instead.

This code works and gives the current time for Colombo.

<?php
date_default_timezone_set('Asia/Colombo');
$time_now=mktime(date('h'),date('i'),date('s'));
$time_now=date('h:i:s',$time_now);
$time_zone=date_default_timezone_get(); //This will show Time Zone
echo "The Current Time Zone is $time_zone and Date is: ";
echo gmdate("M d Y"); //Date Creation
echo " Time is: $time_now";
?>

Just pick the timezone you want from here http://www.php.net/manual/en/timezones.asia.php and run the script. It should work.

0

hi ...

is there any way by using MYSQL , without using PHP....


date & time function using for just displaying time (using in insert query)..

hi ...

Thanks ...

i think the problem with my php version...

can u tell me php version takes from my local system or my server?...i dont know the server php version...

incase if i m using older version of PHP , wat i have to do...

0

You can use

<?php echo 'Current PHP version: ' . phpversion(); ?>

to get the current executing php version. Get the latest version from php.net

You don't need PHP to use MySql. But you need some sort of server side language to sit between your HTML and datastore.

If you're just looking at something to work with MySQL (browsing and management) there are tools to do that as well.

SQL Yog
MySQL CC
Heidi SQL

-1

Hi jomanlk,

Thanks...

Current PHP version: 4.4.9

now. wat can i do....

You can use

<?php echo 'Current PHP version: ' . phpversion(); ?>

to get the current executing php version. Get the latest version from php.net

You don't need PHP to use MySql. But you need some sort of server side language to sit between your HTML and datastore.

If you're just looking at something to work with MySQL (browsing and management) there are tools to do that as well.

SQL Yog
MySQL CC
Heidi SQL

0

All of the above

I believe you's are all doing it wrong other than using the timezone function. There are two ways to achieve this result. One is the date_default_timezone_set() function and the other is the ini_set() function. So I would strongly suggest placing the following code at the top of the php file.

<?php
ini_set('date.timezone','Asia/Calcutta');
echo date('H:i'); //check time

Hope that helps as it should get you on the right track.

0

I believe you's are all doing it wrong other than using the timezone function. There are two ways to achieve this result. One is the date_default_timezone_set() function and the other is the ini_set() function. So I would strongly suggest placing the following code at the top of the php file.

<?php
ini_set('date.timezone','Asia/Calcutta');
echo date('H:i'); //check time

Hope that helps as it should get you on the right track.

Hi Cwarn,

Thanks...

by using ur code...still i m getting the default(different) time...

it displays

03:27

..i think its AM..

but, now my time is

03:53 PM

...dont know wats wrong?

Edited by sarithak: n/a

0

@above.

I am Suggest You That if You are using this code on your local system then Download The New Version of PHP from www.php.net and Install it.
or If you Trying to Run this code on server then tell your Server Administrator for Upgrading Your PHP Version to Latest Version.

I Check Time Function on php.net and Found That There are a Bug in time Function in the Version 4.4. This Version Show One Hours Behind Time of Current Time. for More Please Refer:
http://bugs.php.net/bug.php?id=38392
http://bugs.php.net/bug.php?id=42671

I Hope You Understand.
Thank You.

-1

k...

in my local system, i m using 5+ version....here i m getting local time(correct)...when i run the same code, i m getting wrong time(default time zone)..k


Thanks to all...

i ll try my level best.......

@above.

I am Suggest You That if You are using this code on your local system then Download The New Version of PHP from www.php.net and Install it.
or If you Trying to Run this code on server then tell your Server Administrator for Upgrading Your PHP Version to Latest Version.

I Check Time Function on php.net and Found That There are a Bug in time Function in the Version 4.4. This Version Show One Hours Behind Time of Current Time. for More Please Refer:
http://bugs.php.net/bug.php?id=38392
http://bugs.php.net/bug.php?id=42671

I Hope You Understand.
Thank You.

0

Hi Cwarn,

Thanks...

by using ur code...still i m getting the default(different) time...

it displays ..i think its AM..

but, now my time is ...dont know wats wrong?

Then are you sure your timezone is Asia/Calcutta. Chances are that you will need to change the Asia/Calcutta to something more appropriate. Perhaps a google search for a timezone about 12 hours ahead of Asia/Calcutta will reviel what needs to go into the ini_set function. Just make sure the timezone name is designed for php input and that it is 12 hours ahead of Asia/Calcutta :)

0

Hi
Do not use Calcutta in function date_default_timezone_set().
Use it as -- works perfectly.

date_default_timezone_set("Asia/Kolkata");
0

Hi
Do not use Calcutta in function date_default_timezone_set().
Use it as -- works perfectly.

date_default_timezone_set("Asia/Kolkata");

I suspect sarithak's php time settings may be a bit messed up there for making all timezones 12 hours behind. That is why I say to choose a different timezone at the other side of the world for this job. Just a note.

0

This problem seems to be because your server (i.e. on which your PHP and APACHE is installed and through this you accessing the website in browser) is located in a different timezone than your geographic location - say you are located in India, but your hosting company is in Canada.
What you can see is your server time and you comparing it with your local time.
I will suggest, just ignore this, you should go with the server

Edit: or else you strictly want to do that, just define the new time in some common php file which you include later on. something like -

//This will define the time diff,what you noticing  
$hours_lagging = 4;  
$datetime = strftime(""._DATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],
datetime[2],$datetime[3],$datetime[1]) + (3600 * $hours_lagging) );

Edited by network18: Edit:put code for time addition

0

This problem seems to be because your server (i.e. on which your PHP and APACHE is installed and through this you accessing the website in browser) is located in a different timezone than your geographic location - say you are located in India, but your hosting company is in Canada.
What you can see is your server time and you comparing it with your local time.
I will suggest, just ignore this, you should go with the server

Well said. That is why to avoid situations like this it's best to host on a server in your own timezone or put up with the math of timezone conversion. Generally I'd prefer to do the math but you need to see that the math is there.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.