Jump to content

User date and time


tronicsmasta

Recommended Posts

Hey guys,

 

I would like to use the date() function to input the date into the database but I noticed it goes by the servers time...

 

Is there a way to put in the users date time and timezone so I don't have to ask them their timezone store it in a cookie and then do something like this:

 

eg just an example

$date = date("M j, Y g:i a") + timezone offset?;

Link to comment
https://forums.phpfreaks.com/topic/104660-user-date-and-time/
Share on other sites

 

I am not sure you can get the user's date and time from the server side. You probably need to use Javascript to get the desired date/time then pass that to your PHP script. For example, this Javascript code puts the date/time string into a hidden field of a form and when the user submits the form to PHP code, the date/time is passed along:

 

<form action="some_script.php" method="post" onSubmit="filldate(this)">
<input type="hidden" name="datetime">
Enter you name <input type="text" name="fullname">
<input type="submit" value="send">
</form>
<script>
function filldate(frm)
{
  today = new Date();
  frm.datetime.value = today.toString();
}
</script>

 

You check the Javascript Date() object for more properties that can fit your purpose.

Link to comment
https://forums.phpfreaks.com/topic/104660-user-date-and-time/#findComment-535724
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.