Zen Cart Logo
Forums / General Questions / Cron job to compare time differences

Cron job to compare time differences

Views: 707

Results 1 to 2 of 2
23 Mar 2011, 11:49 AM
#1
totalsam avatar

totalsam

Zen Follower

Join Date:
Jan 2009
Posts:
126
Plugin Contributions:
0

Cron job to compare time differences

Hello,

I am learning as you go with php and trying to create a cron job which will update orders from one status to another after they have been there for 24 hours.

I am struggling to find a way in php to compare the current time with the timestamp on the database so the job knows it needs to be applied.

Anyone got any ideas?

Thanks

23 Mar 2011, 4:53 PM
#2
totalsam avatar

totalsam

Zen Follower

Join Date:
Jan 2009
Posts:
126
Plugin Contributions:
0

Re: Cron job to compare time differences

Problem solved, I needed to convert the MySQL time stamp to a UNIX code.

then I could compare the time() command with the new unix code.

If anyones interested the bit of code to convert MySQL to UNIX is:

function unix_datetime($raw_date = 'now') {
  if ( ($raw_date == '0001-01-01 00:00:00') || ($raw_date == '') ) return false;
  elseif ($raw_date == 'now') {
    $raw_date = date('Y-m-d H:i:s');
  }
  
  $year = substr($raw_date,0,4);
  $month = substr($raw_date,5,2);
  $day = substr($raw_date,8,2);
  $hour = substr($raw_date,11,2);
  $minute = substr($raw_date,14,2);
  $second = substr($raw_date,17,2);
  
  return mktime($hour,$minute,$second,$month,$day,$year);

}

Then you just need to place the following where you want the adjusted date to appear:

unix_datetime(TIME STAMP);