Jump to content

Manipulating Dates (weeks of year number?)


inter

Recommended Posts

Hello all, I have a pretty tough question (for my standards) regarding dates handling in php.

 

I have a date variable called $realdate. Gotten from:

$realdatestring = "20" . $year . $month . $daycounter;
$realdate = strtotime($realdatestring);

 

I have another variable, a timestamp from a mysql table (onupdate current timestamp), called $edited.

 

So I now have 2 datetime variables right?

 

 

I would like to check the $edited variable to see if it's value is more recent than the Friday of the week which the $realdate variable is in.

 

EG: if $realdate is 2008-01-01 (a Tuesday), and $edited is 2008-01-06 (the Sunday)... then $edited is after the Friday of the week that $realdate is a part of.

 

Did that make sense? Lol. I'll try to explain it in other words if that's not clear.

 

Thanks for any input or ideas!

Link to comment
https://forums.phpfreaks.com/topic/89473-manipulating-dates-weeks-of-year-number/
Share on other sites

Give this a shot

 

<?php

$realdate = "2008-01-01";

//We will say this is your timestamp
$edited = time();

//convert timestamp to proper format
$edited = date("Y-m-d", $edited);

//check if $edited is more recent
if ($edited > $realdate){
   echo "Yes, edited date is more recent";
} else {
   echo "No, realdate is more recent";
}

?>

Ok, so thats how I check if it's more recent. Thanks for making that clear :)

 

Do you know if its possible to:

 

I have date variable. I need to find the date of the next Friday that occurs. eg: $date is 2008-01-01 (is a Tuesday), the first following Friday is 2008-01-04.

 

<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
                   // 7 days; 24 hours; 60 mins; 60secs
echo 'Now:       '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
// or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";
?>

http://us3.php.net/manual/en/function.time.php

Unfortunately that code only adds a week regardless of the day.

 

Maybe I could just make a table which stores a hard coded amount.

 

Like..

 

If the day of the week is a Friday, add 0 days.

If the day of the week is a Thursday, add 1 day.

If the day of the week is a Wednesday, add 2 days.

etc.

 

That way it should always find the next friday!

 

The down side is that I dont think I can add times that way, so I couldnt do "5pm Friday", only just "Friday".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.