Jump to content

Archived

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

MysticCoder

Server Time

Recommended Posts

You can also use
[code]$today = date('n/j/Y');[/code]
Only difference is how its formatted when you print it out.
[url=http://www.phpfreaks.com/phpmanual/page/function.date.html]http://www.phpfreaks.com/phpmanual/page/function.date.html[/url]

Share this post


Link to post
Share on other sites
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);";

Share this post


Link to post
Share on other sites
Is this a javascript question or a php question?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Or are you trying to display "today's date at the server", or ...

That is what i'm exactly trying to do, sorry for not clarifying things.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
There's no HTML variables.

To put it into an PHP variable then just assign it...

[code=php:0]
<?php
$today = date("Y-m-d");
echo "Today's server date is $today";
?>
[/code]

Regards
Rich

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
I am trying to get the server date in the form dd/mm/yyyy with the intention of using it as a parameter to another php script.

Share this post


Link to post
Share on other sites
[code]<?php
date = date("Y-m-d"); // or whatever date format you want
include("another_php_script.php"); // uses the date provided
?>[/code]

Share this post


Link to post
Share on other sites
Define 'pass values to the included script'.  The code snippet I posted makes the date variable available to the included script since it's there [i]before[/i] the script gets included.

Share this post


Link to post
Share on other sites
When a html page calls a php script it can post variables to that script.

Can a included php script have variables posted to it in the same manner.

Share this post


Link to post
Share on other sites
http://ca.php.net/manual/en/function.include.php

Look at example 16-7 on that page.

Give that a try.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.