homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

date-time manipulation question
comparing date / time strings

10+ Year Member

Msg#: 11111 posted 3:10 pm on Dec 19, 2005 (gmt 0)

This should be simple, but my brain is rejecting it... here's what I want to do in pseudo code..

//assuming a $_POST was made...
//dealing with date cols in two tables - tbl_1 and tbl_2

$rightnow = date(whatever format);
$targettime = retrieve correct date_col value by query from tbl_1

// here's my question
if($rightnow less than 15 minutes BEFORE $targettime){

//reset date_col in tbl_1 to $rightnow + 15 minutes?

//do nothing

the dates are stored in mysql like 2005-12-19 10:00:58

but I can reformat them if necessary. Is the easiest way to convert all to UNIX timestamp and count the seconds for the comparison?

if anyone knows... thanks



5+ Year Member

Msg#: 11111 posted 4:03 pm on Dec 20, 2005 (gmt 0)

Yes you can use unix_timestamp from within Mysql to convert, and date('U') to get time in php then just compare.


WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 11111 posted 9:20 pm on Dec 21, 2005 (gmt 0)

If the columns are already of type DATETIME I would just run an UPDATE over the table and be done with it. You would specify the MINUTEs to be BETWEEN 0 AND 15 in your WHERE clause.

And Welcome to WebmasterWorld there, Rincewind456.


10+ Year Member

Msg#: 11111 posted 3:02 am on Dec 25, 2005 (gmt 0)

Thanks Coopster.

How I solved it is: (bear in mind that I am lazy and do not code properly) I just used php to translate the raw date string to a unix timestamp, do the math, then (if necessary) translate back to the date string on the fly.

It's for a little auction app that the guy wanted to have the auction close either at the close time listed, or 15 minutes after the last bid - thus the time reset thing. I wanted the date stored in the mysql format because the guy who is going to admin the thing is not that savvy, and he has to put the date in a form manually for each auction he does. So it works great. It's a fairly light traffic, big ticket item auction. My solution might not do well for heavy traffic.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved