-1

My site hosting in filezilla server always saves wrong time in timestamp field in the mysql database..I checked my code in localhost it saves correct time clearly..Timestamp field query is below here

$add_SQL = "insert into applicant (name, createdon) values ('$name', now())";

Is there anything in the filezilla config affects it?
Please help me..Im hanging for 6 days.

Janen R
  • 729
  • 10
  • 21
  • did you check timezone of your server ? – Divyank Mar 08 '17 at 09:22
  • FileZilla is an FTP server, that has nothing to with with your database. – Martin Prikryl Mar 08 '17 at 09:31
  • filezilla server database is located in bangalore(300kms far from chennai)..But I am operating that from chennai..So I cannot change it in php config file...Then I am trying through php code...But couln't..when i print time it shows bangalore time(chennai +5minutes)..But when i insert a new data in database that created_on field(default:CURRENT TIMESTAMP), that saves a strange time(more than 1 hour difference from the correct time)...I tried "date_default_timezone_set('America/Los_Angeles');"..but Its not come..What to do – Janen R Mar 08 '17 at 10:31

1 Answers1

0

If you have admin rights on your database you can change the timezone in the database

Otherwise you can do this with PHP. At the top of your script you should set the timezone, this will ensure that all date/time operations return values related to that timezone.

Then use PHP time() function in your query.

e.g.

date_default_timezone_set('America/Los_Angeles');
...
$add_SQL = "insert into applicant (name, createdon) values ('$name', ".time().")";

Ensure you provide a valid timezone: See list of all possible timezones

Community
  • 1
  • 1
GreensterRox
  • 6,432
  • 2
  • 27
  • 30