Welcome Guest, Not a member yet? Register   Sign In
How to use date function properly?
#1

(This post was last modified: 02-17-2015, 05:00 AM by Vimal.)

I have column name last_updated and datatype is "datetime".

When I use command line and insert "NOW()";
Its working fine but in Codeigniter active records its not working.
I am Currently using
Code:
date('Y-m-d H:i:s');
But its show me date currectly but time is behind than current time.
For example
in command line
Code:
2015-02-17 17:24:51

But with COdeigniter
its insert

Code:
2015-02-17 12:54:50

and
with
Code:
nice_date($last_update, 'd-M-Y h:m a')
its show
17-Feb-2015 12:02 pm
Reply
#2

I think it has nothing to do with the CodeIgniter. It has to do with your server's time which might be different than your computer's time. Or rather with the timezone. You should try putting date_default_timezone_set() in main index.php file (the one that starts up CodeIgniter). Take a look here: http://php.net/manual/en/function.date-d...ne-set.php
Reply
#3

computer time and mysql time is correct Smile
Reply
#4

As mentioned, you need to call date_default_timezone_set() to set the timezone used by PHP's date functions. Given the times you posted, you would likely want to set the timezone to Asia/Kabul or Asia/Calcutta.

Alternatively, you can use date_default_timezone_set('UTC') and convert the dates for display using the proper timezone identifier (i.e. convert the date/time to the current user's timezone).
Reply
#5

Thanx now its ok Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB