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
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";
}

?>

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.