Jump to content

Recommended Posts

Hey,

 

I am trying to send a time and date to my database.

 

The php code is: SET user_last_login = NOW()

This sets it as:  2012-08-02 06:22:34

 

However this is 5 hours earlier than I want it. How can I change this so that it sets the timezone as GMT (Europe/London).

 

I have tried changing the Global TimeZone in phpMyAdmin, and it says I need SUPER PRIVELIDGES to do so. I have tried date_default_timezone_set('Europe/London') and this also does not work.

 

Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/266590-help-mysql-query-timestamp/
Share on other sites

No time was acctually displayed.  :shrug:

 

What do you mean?

echo date("m/d/y",time());

This is specifically telling it to display only month, day and year in the first parameter ("m/d/y"). This however will include a 24 hour time at the end.

 

echo date("m/d/y H:i:s",time());

 

What's the different times produced if you try different locations in date_default_timezone_set(); Does "Europe/Paris" output 1 hour later?

 

And I don't think date_default_timezone_set() will affect MySQL's NOW(), only PHP's time(). I guess your server has the wrong settings (not set timezone correctly or wrong time).

 

I also don't think date_default_timezone_set() will affect the timestamp itself. If you change it, time() will show the time number, but when you convert it with date() it will show different times based on timezone. The timestamp is universal.

Ok so I echo'd the code below and changed the date_default_timezone_set to Europe/London and it gave the correct time, and then changed it to Europe/Paris and it displayed a time 1 hour in front. So it seams that code is working.

date("m/d/y H:i:s",time());

 

Now I need to get this date and time in to my database. Using NOW() still gives a time 5 hours behind. If i define the code above as variable $datetimestamp and then use the code below would that work? I would probably have to change the database column to varchar?

SET user_last_login = '$datetimestamp' 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.