date problem

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
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

date problem

Post by gurjit »

hi all,

how do i get the date for the nearest friday lets say 6 weeks from today.

so if the date lets say was stored in the database as:
2005-11-15

then i need 6 weeks and closest friday which would give me:
2005-12-30
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

This will give you the nearest friday *after* 6 weeks so you always get at least 6 weeks.

Code: Select all

$next_fri = strtotime('next friday'); //Gets timestamp for midnight on the next friday (or today if today is friday)

$_6_wks_fri = strtotime('+6 weeks', $next_fri);

echo date('jS M Y', $_6_wks_fri);
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

hi d11wtq,

that works great but how can i make

Code: Select all

<?php
$next_fri = strtotime('next friday'); //Gets timestamp for midnight on the next friday (or today if today is friday) 
?>
a variable date. I have to pull the date out of a database and it needs to calculate the closest friday and then 6 weeks from there????
Post Reply