0

ok so i believe that i should know this but i have not really dove into dates with php. Ok so what i am trying to do is find the latest date between 2 dates. And if the dates are the same then find the latest time then echo out the the latest file

$fileonedate = date("m/d/Y",filemtime("page1.php"));

$filetwodate = date("m/d/Y",filemtime("page2.php"));

$fileonetime = date("H:i:s",filemtime("page1.php"));

$filetwotime = date("H:i:s",filemtime("page2.php"));

thanks in advance

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by itisnot_me
0

Compare the filetimes, then format the one you want to have.

$format = 'm/d/Y H:i:s';
if ($t1 = filemtime('page1.php') < ($t2 = filemtime('page2.php'))
  $filetime = date( $format, $t2 );
else
  $filetime = date( $format, $t1 );
0

so lets say that i was going to grab edit dates within the database would i do the same thing

$dateone = "03/13/2011 3:24:32";
$datetwo = "03/13/2011 3:54:21";

if ($dateone > $datetwo)
{
echo "Date one";
}else{
echo "Date two";
}

that seems to work but i just want to make sure that im doing it correctly.

0

What are "edit dates"?
And no, the comparison operators < = > in PHP do string or numeric comparison but not date formats. So you have to format the dates to be compared in the order Y-m-d H:m:i.

0

a edit date is when someone has edited the DB entry. i capture the time and put it to the DB.

ok so if i understand i have to save the dates like this (im not sure what the m is in H:m:i i think you mean H:i:s )

$dateone = "2011/03/13 15:24:32";
$datetwo = "2011/03/13 15:54:21";

if ($dateone > $datetwo)
{
echo "Date one";
}else{
echo "Date two";
}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.