Jump to content


Photo

Server Time


  • Please log in to reply
18 replies to this topic

#1 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 September 2006 - 02:25 PM

Hi,

How do I retrieve the server's date and time in the format dd/mm/yyyy?

Thanks,
Boulent

#2 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 04 September 2006 - 02:26 PM

I think it would be
$timevar = date("d/m/Y");


#3 Ghostu

Ghostu
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 04 September 2006 - 02:49 PM

You can also use
$today = date('n/j/Y');
Only difference is how its formatted when you print it out.
http://www.phpfreaks...ction.date.html

#4 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 September 2006 - 03:03 PM

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);";


#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 September 2006 - 03:05 PM

Is this a javascript question or a php question?
Legend has it that reading the manual never killed anyone.
My site

#6 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 September 2006 - 03:06 PM

Php, I have a php script been called by a javascript.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 September 2006 - 03:15 PM

Php, I have a php script been called by a javascript.


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.
Legend has it that reading the manual never killed anyone.
My site

#8 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 04 September 2006 - 03:24 PM

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.

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 September 2006 - 03:29 PM

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):

<?php
echo "Today's server date is ". date("Y-m-d"); // or any format you want - check the date() function in the manual
?>

Legend has it that reading the manual never killed anyone.
My site

#10 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 September 2006 - 12:28 PM

How do you store the echoed value in a html variable?

#11 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 05 September 2006 - 12:32 PM

There's no HTML variables.

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

<?php
$today = date("Y-m-d");
echo "Today's server date is $today";
?>

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#12 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 12:33 PM

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?
Legend has it that reading the manual never killed anyone.
My site

#13 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 September 2006 - 12:35 PM

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.

#14 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 12:39 PM

<?php
date = date("Y-m-d"); // or whatever date format you want
include("another_php_script.php"); // uses the date provided
?>

Legend has it that reading the manual never killed anyone.
My site

#15 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 September 2006 - 03:05 PM

How would you pass values to the included script?

Thanks,


#16 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 03:12 PM

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 before the script gets included.
Legend has it that reading the manual never killed anyone.
My site

#17 MysticCoder

MysticCoder
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 September 2006 - 03:18 PM

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.

#18 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 September 2006 - 03:32 PM

http://ca.php.net/ma...ion.include.php

Look at example 16-7 on that page.

Give that a try.
Legend has it that reading the manual never killed anyone.
My site

#19 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 05 September 2006 - 03:33 PM

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?

When a html page calls a php script it can post variables to that script.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users