time date

I have a form that posts to a text file along with the other data that users fill in I have been asked to include time and date… It works yet I am also getting an extra character 1 … It’s not a huge deal, ;east to me it isn’t, but the boss may not like it much…

What I’m using is:
[php]
$date = date(“D F j,Y g:ia I”);

[/php]

The results looks like:

date Tue April 17,2012 6:33pm 1

What am I doing wrong?

Thank you for any help.
~Grall~

ok maybe I’m too tired …
But can’t seem to get the right timezone on it either…

hello Grall14k,

Use this code
$date = date(“D F j,Y g:ia”);

your getting extra character 1 because of “I” used by you in date(“D F j,Y g:ia I”); function. remove it.

SR

Thank you for the reply…
That got rid of the extra character but the time showing is still an hour off, behind, am guessing this is because of daylight savings?? Is there a way to fix this??

~Grall~

hello Grall14k,

i think this happen because of time zone difference
try(use) below code.
$y = gmdate(‘Y’);
$m = gmdate(‘m’);
$d = gmdate(“d”);
$date = gmdate(“D F j,Y g:i a”,mktime(12, 0, 0,$m ,$d,$y));

instead of below code
$date = date(“D F j,Y g:ia”);

SR

thanks again for the reply.
That changed it to show 5:00pm not the current time in EDT

~Grall~

hello Grall14k,

can you provide an example of output you are expected.

SR

I am looking to have day of the week Month day, year time (current EDT or EST as the case may be)
Wed April 18,2012 8:18 am

Thank you
~Grall~

Grall, are you talking about using a timestamp in your program on your server? If you use PHP in a webpage on your server and use the “date” or “time” or “strtotime” functions, you will ALWAYS get the SERVER’s timezone?
You can try to pull the client’s timezone, but, not all server’s will pull the clients timezone.
Usually, you have to do that on the browser or CLIENT-SIDE as the server is not usually the same as the user’s location.

If you need to use the time from the client’s system, you can do that with Javascript and pull it from their local machine. You can do that when they log in and save it in your database with a time difference so when they display time functions, you can adjust the time for them.

So, if they post something and you timestamp it and they are in a different timezone, the wrong time will be posted. When displayed back, it will be off up to 3 hours in the US.

SOLUTIONS: So, now that I have said all that… You can solve this by two ways. You can have the user enter their timezone when they register and adjust the time using their setting. (There are date/time functions in PHP to do this.) Or, instead of having them involved, you can store a “local zone cookie” on their system and read the data back in PHP to find the difference in time from your server to their local machine and use that difference when displaying times on their computer… Here is a quote I found on another site about this:

Sometimes, there's not a server-based/PHP method for getting local time. You have to get it from the client via Javascript. Google "bitbucket timezone detect" and use it to set a "local_timezone" cookie that you can read from PHP and set via date_default_timezone_set()
Hope some of that info helps you...

Thank you very much for your reply…
I had after much digging around found that you are right… The time I am seeing is indeed what our server is on… I had hoped to be able to set that script to “our” time - Eastern because that is the timezone the radio station I work for goes by… Not really that big a deal, we will work with what we have… Thank you very much for your help…

~Grall~

at the top of yer script (yes each script, can be included) add date_default_timezone_set which affects all timedate functions :slight_smile:

Well, if you just want to use YOUR timezone for all displays, like Laffin stated, this can be done.
If you want to adjust the timezone so YOUR time is translated to THEIR timezone, that can be done too.
Just depends what you are trying to get out there… I have seen some sites that just post the time of the server with a note after it, like: 9:32PM (EST) And, that seems to be a fine for most people as they know the timezone alters 1 to 3 hours… Well, good luck with your project…

the project is a request script/form that a listener fills out with their name, song title, artist and a dedication if they are so inclined… The form posts to a html page that my DJs can access during a show.
My boss asked if I could include a time/date stamp in the results that he sees… Looking something like this:

Name: test
Artist:
Song:
Dedication:
date Tue April 20,2012 12:10pm

Right now it shows Central time instead of Eastern… As I said before not that huge a deal since listeners do not see what the form puts out… I just thought it would be a good idea for my DJs…
As I am still a beginner & learning at php I had thought to ask help…
I can post the whole script if anyone needs/wants me too, not sure that would help anything…

Thank you for your replies
~Grall~

Well, just use the time zone functions. There are many available. They work like this:

$timezone = new DateTimeZone(“America/Los_Angeles”);

Here is a list of others. Note the areas on the right:
http://www.php.net/manual/en/timezones.others.php

There are commands to set the local timezone. If you execute that command, the ones displayed will show as if they are in that timezone.

To show the time zone in the server, use this command: echo date_default_timezone_get();

Well, hope that helps…

[size=12pt][font=comic sans ms]Wanted to stop in and post the solution ErnieAlex provided for me.[/font][/size]

[size=12pt][font=comic sans ms]The boss is very happy with the end result BIG thank you to Ernie…

~Grall~[/font][/size]

Glad we could help you out… Please come back again!!!

CYA in the bitstream...

[font=comic sans ms][size=10pt]Will do! lol the boss has been thinking, (scary), never know what he has in mind or wants for the site… lol

~Grall~[/size][/font]

Sponsor our Newsletter | Privacy Policy | Terms of Service