daveWare Posted February 28, 2006 Share Posted February 28, 2006 On my contact form I want to include a date of when the submission took place. I've added the date function to my processor page: $today = date("m/d/Y H:i"); Now how do I add 3 hours to account for the difference in time zone. the server is running php 4.4.1.I know this is something simple but every combination so far doesn't work. Being new to programming I figure its time to call for help.Thanks,Dave Link to comment Share on other sites More sharing options...
sbrownii Posted February 28, 2006 Share Posted February 28, 2006 Read about the date() and mktime() functions:http://us2.php.net/manual/en/function.date.phphttp://us2.php.net/manual/en/function.mktime.phpIf you read through those 2 pages, you will find your answer. Actually, if you just look at the examples OR usernotes, you will find your answer!You could also read the user notes on the gmdate pagehttp://us2.php.net/manual/en/function.gmdate.php#usernotesThese are links to particular entries that exactly solve your problem:http://us2.php.net/manual/en/function.gmdate.php#58773http://us2.php.net/manual/en/function.date.php#61674 Link to comment Share on other sites More sharing options...
daveWare Posted February 28, 2006 Author Share Posted February 28, 2006 Okay, I reread the pages you suggested and put this: $today = theDate($date, $time);function theDate($date, $time) {$timeDiff = 7 + date('I'); /* the "date('I')" part is where it accounts for day light savings. */$timeZone = time() - ($timeDiff*60*60);$date = date('m/d/Y',$timeZone);$time = date('H:i',$timeZone);} In my PHP, When I look at the database nothing has been entered into the dateEntry field. Same thing that happened before. Any ideas what I'm doing wrong?Further information; this is my INSERT statement INSERT INTO contact_tbl (dateEntry, fname, lname, address1, address2, city, state, zip, email, phone) VALUES ('$today', '$first', '$last', '$add1', '$add2', '$city', '$state', '$zip', '$email', '$phone')"; Thanks,Dave Link to comment Share on other sites More sharing options...
sbrownii Posted March 1, 2006 Share Posted March 1, 2006 Have you tried to echo the value of "$today" ?Your code says: $today = theDate($date, $time); But your function "theDate()" returns no value... not sure why you are passing $date and $time to it either...Rewrite "theDate()" to take no parameters and actually return a value. The return value should be the date that you want to be stored in $today.remove the lines that assign values to $date and $time (get rid of those variables all together) and put something like this at the end of the function. return date('m/d/Y H:i',$timeZone); You can, of course, adjust the format of the date how you like ( I just based it on what you where doing already ), but it does need to be returned as a single value.I guess you are pretty much on the right track.You do realize that "theDate()" is subtracting 7 hours from the time on the server?You said you needed to add 3 hours - so you should change the "7" to "3" and then add "($timeDiff*60*60)" to $time instead of subtracting. Link to comment Share on other sites More sharing options...
daveWare Posted March 1, 2006 Author Share Posted March 1, 2006 Brilliant!I put the code into a function because I wasn't sure how to get the $time and $date variables into the $today variable. your solution simplified the code and I didn't really need the function at all. Best of all it works. I don't know why I didn' t think of it my self. I hadn't really worried about the math til last. I was more worried about it working. In case your interested here is the final code: /* Create the date Timestamp */$timeDiff = 3 + date('I'); /* the "date('I')" part is where it accounts for day light savings. */$timeZone = time() + ($timeDiff*60*60);$today = date('m/d/Y H:i',$timeZone); Thank you so much for your help!Dave Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now