Setting and stamping time on submit with php - php

I'm fairly green to PHP and I'm looking for a way to stamp time when a user, submits the form. I only want that time and not the current time. I have tried a few things like print, echo etc. But I can't seem to understand it properly.
Additionally to this my server time is returning a time that is an hour fast. I have tried to combat this with the following but no with no luck.
heres what I have;
// The following script only executes when the form is processed.
// set server timezone. declared at the top of my document.
date_default_timezone_set("Europe/London" . '-1');
// set date & time. placed within my isset submit argument.
$date = date ("l, F jS, Y");
$time = date ("h:i A");
I'm currently calling the these variables with echo and EOD but, this is always giving me the server time even if the page is refreshed. I'm looking for a stamp of the time.
I'm echoing these variables out within an EOD and as a result, the print. command is being converted to simple text.
would anyone know of a quick fix to this or am I being a little too green?

In your script, try just:
date_default_timezone_set("Europe/London");
If that is the timezone you want your script to use.
Then on your server, make sure the server is set to use UTC (Coordinated Universal Time). That is a server set up issue.
https://www.devside.net/wamp-server/setting-the-default-timezone-for-php-to-use

Related

Why time() function returns different values on different servers?

When I write this line of code on local, the output will be this:
echo time(); // 1464605083
And when I write in on the 3v4l (online PHP shell) the output will be this:
echo time(); // 1339412843
As you see there is a huge different between those outputs. What's wrong? And how can I sync them?
Note: I'm using Xampp on my local.
If the time you got back from the code is not the right time, it's probably because your server is in another country or set up for a different timezone.
So, if you need the time to be correct according to a specific location, you can set a timezone to use.
The example below sets the timezone to "America/New_York", then outputs the current time in the specified format:
<?php
date_default_timezone_set("America/New_York");
echo "The time is " . date("h:i:sa");
?>
That timezone will be vary according to the servers you are using. If you want to use same timezone in all your server. Use
date_default_timezone_set('timezonename')
use timezone i hope it's work ...
<?php
date_default_timezone_set('America/New_York');
echo $date= time() ;
?>
The webserver where you are testing this has a completely off system time set.
If you look at the date of your test script (right next to the title field) you'll see that it has been saved at # Mon Jun 11 2012 11:07:23.
Your timestamp 1339412843 translates to 06/11/2012 # 11:07am (UTC).
So, the server time is just wrong. Test your script someplace else if time is critical.

PHP date() not returning correct time?

I'm trying to figure out why my current PHP date() function is not returning the correct time.
As of this moment, my real-life date/time is 2015:10:23 18:49(sec), however for some reason when I run my php code, I get 2015-10-24 00:49:15. For some reason it thinks I'm 6hrs ahead? I'm in Eastern Standard Time by the way, in case it helps.
PHP
$today = date("Y-m-d H:i:s");
echo "The date and time right now is " . $today;
I'm attempting to code the current date/time into my MySQL database, to log when a member created their account (and later update to log when why last logged in). How do I fix this so it's correct for anyone who uses it?
include this line on the top of your php code.
date_default_timezone_set('Asia/Beirut');
while instead of asia/beirut, get your country..
check the link to see all supported countries
http://php.net/manual/en/timezones.php

PHP Winter Time in Europe/Athens

in the php.ini I defined the timezone to Europe/Athens. Everything was just fine until last sunday, when the time chanegd to WINTER TIME. The time went back in 1 hour.
The problem is, that in my website - it's still like summer time, didn't go back in 1 hour... I checked it in other website and it's ok there - http://www.timeanddate.com/worldclock/city.html?n=26
To make sure, I added this line in the top of the page:
ini_set('date.timezone', 'Europe/Athens');
But it dind't help...
What heppent? How can I fix it?
I think this will help you.
date_default_timezone_set('Europe/Athens');
If you just set the default time in the start of your function or program the date is format in the country you want.
<?php
date_default_timezone_set('Europe/Athens') ;
echo "the date is:". date("d/m/Y")."<br/>";
echo "the time is:". date("h:i:s");
?>
Just two little hints:
Please check if the output of following code returns your timezone:
$date = new DateTime();
$tz = $date->getTimezone();
echo $tz->getName();
Which function or language do you use to display the time on your website? Perhaps javascript? Then the time comes from the client system.
You might consider updating your PHP time zone database. You can find the latest version here.
However, I checked through the database and it looks like Europe/Athens has been in sync with EU since 1981, which has used the Last Sunday in October since 1996. So even if you have a very old database I can't imagine that it would be incorrect for recent dates.

Php Date Function

I have tried using php date function() like as follows
$date=date('Y-m-d').' '.date('H:i:s');
echo $date;
the output displayed is 2013-04-03 09:04:02.. but my system is 02:49 pm...
What time is being displayed for me? I tried changing the internet timing even then I am getting the same answer ?
First off, it is not necessary to use the date function twice. This will do the same thing:
echo date('Y-m-d H:i:s');
Second, you need to set PHP's date.timezone. This can be done in the php.ini file, but it can also be done using the date_default_timezone_set function, like this:
date_default_timezone_set('Europe/Amsterdam');
The string that you have to put in can be found in the documentation.
It may also be worth noting that you can tell the date function to use any time. This is done by passing in a *nix timestamp as the second argument. For example:
// One week ago from now
echo date('Y-m-d H:i:s', time()-604800);
It will show server's time only. If possible compare with your server time. If you want to use local machine's time you need to go with JAVASCRIPT.
And another suggestion,
You don't have to use individually to display date & time. You can achieve this in a single statement like this.
$date=date('Y-m-d H:i:s');
You will get the same format 2013-04-03 09:04:02
check for your system timezone and your default timezone in php by opening phpinfo()

cannot get the correct date and time in php

I dont know why I'm not getting the correct date and time in my region.
Here's the code
<?php
//date_default_timezone_set('Asia/Manila');
echo date('YYYY-mm-dd H:i:s'); ?>
Even if I comment out or change the time zone the date and time that I'm getting is still the same.
The date today is 23. But its outputting 22. And the time doesn't change even if I change the time zones.
Does it have something to do with my computer?
Because I sometimes notice that the clock on the lower right corner of the screen is not displaying the correct time.
Heres the current time, but its displaying this:
01-22-2011 05:38:31-PM
Are you sure that's the script producing the output shown?
echo date('YYYY-mm-dd H:i:s'); ?>
Doesn't seem to match the format of
01-22-2011 05:38:31-PM
Other than that, the timezone setting looks right.
It could be that time set up on server (where PHP script is being executed) is not correct.
Are you from the Philippines? This worked for me for some reason:
date_default_timezone_set('Asia/Tbilisi');
Asia/Manila is not working for me too. Just give it a try.

Categories