Necuima Posted September 4, 2012 Share Posted September 4, 2012 Hi Larry, After quite a bit of delay, I have been working through the book - great!! I have managed to get both the non-AJAX and AJAX auction sites working but have a question re closed bids (page 567). The index script only lists open auctions, so, without fiddling, how does one get the 'auction closed' message? Thanks, Necuima. Link to comment Share on other sites More sharing options...
Larry Posted September 5, 2012 Share Posted September 5, 2012 Thanks for the nice words. To do that, you'd need to modify the query on the index page to list all the auctions. Link to comment Share on other sites More sharing options...
Necuima Posted September 6, 2012 Author Share Posted September 6, 2012 Hi Larry, OK, I have modified the query and also put in a crude test to change the 'closes' heading message to 'closed' if the auction close date/time has passed. I'm not particularly happy with my 'crude' test but it seems to work OK. I need to do some more study to better understand the UTC date-time / local date-time approach (which makes good sense in this context) and how to code for it appropriately! Thanks again for a great book! Cheers from Oz. Link to comment Share on other sites More sharing options...
Larry Posted September 7, 2012 Share Posted September 7, 2012 Great. Thanks for the nice words! Link to comment Share on other sites More sharing options...
Necuima Posted September 7, 2012 Author Share Posted September 7, 2012 Hi Larry, I have been experimenting with PHP and dates and have the following query: If I code: $utc = strtotime(gmdate("Y-m-d H:i:s")); I get a Unix timestamp for UTC. But if I code: $utcU = gmdate("U"); I get a Unix timestamp for my local time zone. I am obviously mis-understanding gmdate with the "U" parameter. I thought that gmdate returns UTC and that the "U" parameter gives you a Unix timetstamp. Can you please help me understand this? Thanks, and cheers. Link to comment Share on other sites More sharing options...
Larry Posted September 7, 2012 Share Posted September 7, 2012 gmdate() returns Greenwich Mean Time. If you just want the Unix timestamp for GMT, use the gmmktime() function. Link to comment Share on other sites More sharing options...
Necuima Posted September 8, 2012 Author Share Posted September 8, 2012 Hi Larry, I tried: $utcU = gmmktime(); but it returns the timestamp for my timezone, not GMT/UTC? I can't see where/if a parameter needs to be supplied to indicate that I'm wanting GMT/UTC? To make my question clear, I am looking for the current UTC/GMT time, i.e., the GMT/UTC UNIX timestamp for the time at which I run the script. Again, any advice will be appreciated. Thanks, Necuima. Link to comment Share on other sites More sharing options...
Larry Posted September 10, 2012 Share Posted September 10, 2012 This may sound silly, but can you confirm how you know it's returning the timestamp for your timezone and not GMT? Link to comment Share on other sites More sharing options...
Necuima Posted September 10, 2012 Author Share Posted September 10, 2012 Hi Larry, It is not a silly question at all - in fact I have been pondering this in some depth over the last few days. Here's my logic: 1) I do gmdate("Y-m-d H:i:s") and then print it out and it is indeed UTC/GMT. 2) I parse out the values and then do $utcxx = mktime($hour, $min, $sec, $mm, $dd, $yr) (page 114 of your PHP & MySQL book 2nd edition) 3) I var_dump $utcxx and it gives me a timestamp. 4) I then do $utcU = gmmktime() and then var_dump it out and it gives me a different timestamp. 5) I then subtract the step 2 timestamp value from the step 4 timestamp value, divide by 3600, and it gives the correct time differential between my time zone and UTC (+10 hours). Thus I conclude that the gmmktime function gives me a timestamp value for my location, not GMT/UTC. Am I going nuts?? Thanks, Necuima. Link to comment Share on other sites More sharing options...
Larry Posted September 14, 2012 Share Posted September 14, 2012 Learning something new...I just tested this myself and gmmktime() and mktime() were returning the same values when called with no arguments. I read through the user comments on the gmmktime() and someone pointed out that this is the case. However, if you proved any arguments, such as just the hour, it works: echo (gmmktime(14) - mktime(14)) / 3600; Link to comment Share on other sites More sharing options...
Necuima Posted September 15, 2012 Author Share Posted September 15, 2012 Hi Larry, Thanks for checking this out. I was wondering if I was going a bit crazy!! I have tried putting an hour (an integer) in gmmktime and it gives varying results depending on what integer you use and what time of day you run the script. Your echo above works just fine for the time differential, but the gmmktime(n) function on its own will not give you a timestamp for GMT unless you use the correct value for 'n', and that value is not the time differential between your time zone and GMT (well it may be for one particular hour of the day). Weird eh! I suggest that we close this thread. From my tinkering about I can reliably get the timestamp for GMT/UTC via the code in an earlier post. Thank you for your interest. Best regards from Oz. Link to comment Share on other sites More sharing options...
Larry Posted September 17, 2012 Share Posted September 17, 2012 Great. Thanks for sharing. I always create my UTC timestamps in the database, so I had not seen this before. Link to comment Share on other sites More sharing options...
Recommended Posts