Jump to content

Recommended Posts

August 13, 1978 was a Sunday.  This will get the info, that the next time August 13 happens on Sunday is in 1989.  There may be a better way, but this is what I came up with.

 

<?php
$date = new DateTime('1978-08-13');
$findDate = $date->format('l');
$interval = $date->add(new DateInterval('P1Y'));
while($date->format('l') != $findDate) {
$date->add(new DateInterval('P1Y'));
}
echo $date->format('l F d, Y');
?>

http://www.php.net/manual/en/datetime.installation.php

Note: Experimental DateTime support in PHP 5.1.x

Although the DateTime class (and related functions) are enabled by default since PHP 5.2.0, it is possible to add experimental support into PHP 5.1.x by using the following flag before configure/compile: CFLAGS=-DEXPERIMENTAL_DATE_SUPPORT=1

I did it both ways. So you could use either one.

<?php
//Object Oriented.
echo 'Object Oriented.<br />';
$date = new DateTime('1978-08-13');
$findDate = $date->format('l');
$interval = $date->add(new DateInterval('P1Y'));
while($date->format('l') != $findDate) {
$date->add(new DateInterval('P1Y'));
}
echo $date->format('l F d, Y');

//Procedural
echo '<br /><br />Procedural<br/>';
$date = strtotime('1978-08-13');
$findDate = date('l',$date);
$interval = strtotime('+1 Year',$date);
$current = date('l',$interval);
while($current != $findDate) {
$interval = strtotime('+1 Year',$interval);
$current = date('l',$interval);
}
echo date('l F d, Y',$interval);
?>

Try this:

$month = '08';
$day = '13';
$year = '1978';
$date = strtotime($year.'-'.$month.'-'.$day);
$findDate = date('l',$date);
$interval = strtotime('+1 Year',strtotime(date('Y').'-'.$month.'-'.$day));
$current = date('l',$interval);
while($current != $findDate) {
$interval = strtotime('+1 Year',$interval);
$current = date('l',$interval);
}
echo date('l F d, Y',$interval);

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.