Jump to content

Recommended Posts

I tried but am having no joy in getting it to display today's date.

The original script shown below works but it displays elements I am not interested in.
// Get server date
$mydate = date("U"); // date("U"); //

// Get Timezone offset
$myoffs = date("Z") - $myServerOffset;

// Adjust offsets for local machine
//print "var tzoffset =  $myoffs + (new Date().getTimezoneOffset()*60);";
print "var tzoffset = $myoffs +(new Date().getTimezoneOffset()*60);";
// Set JavaScript variable to your server time as seen from client machine's location.
print "var servertimeOBJ=new Date(($mydate+tzoffset)*1000);";
Link to comment
https://forums.phpfreaks.com/topic/19671-server-time/#findComment-85755
Share on other sites

[quote author=MysticCoder link=topic=106844.msg427773#msg427773 date=1157382417]
Php, I have a php script been called by a javascript.
[/quote]

I don't understand that, but I thought you were trying to display "today's date" correctly for a user regardless of where they were on the planet - which is pure javascript - and nothing to do with the date/time on your server.  Or are you trying to display "today's date at the server", or ...

Maybe you could clarify that for us.
Link to comment
https://forums.phpfreaks.com/topic/19671-server-time/#findComment-85765
Share on other sites

Then it should be as simple as a little piece of php code inserted whereever you want it (on a page with a  .php extension):

[code]<?php
echo "Today's server date is ". date("Y-m-d"); // or any format you want - check the date() function in the manual
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/19671-server-time/#findComment-85778
Share on other sites

What do you mean by 'html variable' - there's no such thing.  You can echo the server date as many times as you want to in your html code if you just want to use it many times on the same page.

Are you trying to get the server date AND then use it in a piece of javascript somehow?
Link to comment
https://forums.phpfreaks.com/topic/19671-server-time/#findComment-86304
Share on other sites

When you include a php script into another php script. The file that is being included is merged with the parent file, so it becomes one file effectively. So what ever variables you use in the parent file, those variables can be used in the included file.

Or am I not understanding what you are asking?

[quote]When a html page calls a php script it can post variables to that script.[/quote]
By that do you mean variables in the URL, eg mysite.com/page.php?var=something
Then in page.php you use $_GET['var'] to get the var variable? If thats the case you can do that. However you'll have to use an absolute path (http://mysqite.com/path/to/file.php) to the file you are including and make sure that the allow_url_fopen direcive is set to on in the php.ini
Link to comment
https://forums.phpfreaks.com/topic/19671-server-time/#findComment-86466
Share on other sites

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.