Date/Time Minus -- date(); [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Date/Time Minus -- date(); [SOLVED]

Post by tecktalkcm0391 »

I have the date as:

Code: Select all

$old_time = date("F n, Y H:i:s");
$more = 4;
How do I make it add $more hours to the $old_time and then compare it to the current time

Code: Select all

$current = date("F n, Y H:i:s");
and if the new time is >= current time, then it returns false, otherwise it returns true.

NOTE: the old_time is comming from a database entry. not date("F n, Y H:i:s");
Last edited by tecktalkcm0391 on Fri Jun 16, 2006 11:10 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Perhaps..

Code: Select all

$more = 4;
$current = date("F n, Y H:i:s", strtotime('+'. $more .' hours', time()));
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: Date/Time Minus -- date();

Post by aerodromoi »

tecktalkcm0391 wrote:I have the date as:

Code: Select all

$old_time = date("F n, Y H:i:s");
$more = 4;
How do I make it add $more hours to the $old_time and then compare it to the current time

Code: Select all

$current = date("F n, Y H:i:s");
and if the new time is >= current time, then it returns false, otherwise it returns true.

NOTE: the old_time is comming from a database entry. not date("F n, Y H:i:s");
If I recall the function correctly, F means January through December and n (months as well) 1-12. So where's the day?

aerodromoi
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

opps, i'll fix that n to j

opps, i'll fix that n to j


[quote="Jcart"]Perhaps..

Code: Select all

$more = 4;
$current = date("F n, Y H:i:s", strtotime('+'. $more .' hours', time()));
[/quote

Ok, well how would you do it if it was like this for $old_time

Code: Select all

$get_update = mysql_query("SELECT * FROM `update`");
$get = mysql_fetch_array($get_update)
$old_time = $get['OldTime'];

$more = 4;
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Post by aerodromoi »

How about:

Code: Select all

<?php
function checktime($dbdate){
  $dbtime = strtotime($dbdate)+4*3600;
  $ctime = date("U");
  
  return ($dbtime >= $ctime) ? false : true;
}

//$dbdate = "January 01, 1999 02:22:13";
$dbdate = "June 16, 2006 19:07:13";

if(!checktime($dbdate)) {echo "entry less than (or exactly) four hours old";}
else {echo "entry more than four hours old";}
?>
aerodromoi
Post Reply