Adding/Calculating time with php.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nickuss04
Forum Newbie
Posts: 1
Joined: Thu Jan 29, 2004 6:41 am

Adding/Calculating time with php.

Post by nickuss04 »

Hi,

I'm a newbie here and reletivly new to php, i hope any of you can help.

What im wanting to do is show two times on a web page. The first time is the time that is taken from the server with the date() function, the second is a calculated time. (ie. calculating the time of one country from the server time of the other).

Can anyone suggest some PHP code to take the time from the server and add 5 hours to it while still displaying the proper AM or PM and reseting the hour back to 1 oclock after it go's past 12 oclock. The date dunction that im using is date(g:i A) to show eg. "3:45 PM".

If anybody could help, that would be great.

Cheers...Nickuss.
User avatar
Derfel Cadarn
Forum Contributor
Posts: 193
Joined: Thu Jul 17, 2003 12:02 pm
Location: Berlin, Germany

Post by Derfel Cadarn »

Before asking others to code for you. I'd suggest you read time and date functions in the php-manual. You could play a bit with those?!? :lol:
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Definitely look at the php manual. One piece of advice I can give you is do all your adding/subtracting to the UNIX timestamp, rather than a prettily formatted date. It's much easier to work with and you don't have to worry about noon/midnight rollovers.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply