MysticCoder Posted September 4, 2006 Share Posted September 4, 2006 Hi,How do I retrieve the server's date and time in the format dd/mm/yyyy?Thanks,Boulent Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 4, 2006 Share Posted September 4, 2006 I think it would be[code]$timevar = date("d/m/Y");[/code] Quote Link to comment Share on other sites More sharing options...
Ghostu Posted September 4, 2006 Share Posted September 4, 2006 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] Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 4, 2006 Author Share Posted September 4, 2006 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);"; Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 Is this a javascript question or a php question? Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 4, 2006 Author Share Posted September 4, 2006 Php, I have a php script been called by a javascript. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 [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. Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 4, 2006 Author Share Posted September 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 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]<?phpecho "Today's server date is ". date("Y-m-d"); // or any format you want - check the date() function in the manual?>[/code] Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 5, 2006 Author Share Posted September 5, 2006 How do you store the echoed value in a html variable? Quote Link to comment Share on other sites More sharing options...
HuggieBear Posted September 5, 2006 Share Posted September 5, 2006 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]RegardsRich Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 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? Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 5, 2006 Author Share Posted September 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 [code]<?phpdate = date("Y-m-d"); // or whatever date format you wantinclude("another_php_script.php"); // uses the date provided?>[/code] Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 5, 2006 Author Share Posted September 5, 2006 How would you pass values to the included script?Thanks, Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
MysticCoder Posted September 5, 2006 Author Share Posted September 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 5, 2006 Share Posted September 5, 2006 http://ca.php.net/manual/en/function.include.phpLook at example 16-7 on that page.Give that a try. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted September 5, 2006 Share Posted September 5, 2006 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=somethingThen 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.