Welcome to WebmasterWorld Guest from 54.163.168.15

Forum Moderators: coopster & jatar k

date-time manipulation question

comparing date / time strings

   
3:10 pm on Dec 19, 2005 (gmt 0)

10+ Year Member



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?

}else{
//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

4:03 pm on Dec 20, 2005 (gmt 0)

5+ Year Member



Yes you can use unix_timestamp from within Mysql to convert, and date('U') to get time in php then just compare.
9:20 pm on Dec 21, 2005 (gmt 0)

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



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.

3:02 am on Dec 25, 2005 (gmt 0)

10+ Year Member



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.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month