By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Daycount problem

P: n/a
Ich want to count the days between the current day an the birthday next
Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday: 07.06.1977.
How can I calculate the days to the next birthday ??

Please help me !! Thanks Fraya Pohl
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
*** Fraya Pohl wrote/escribió (1 Jul 2004 01:41:27 -0500):
Ich want to count the days between the current day an the birthday next
Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday: 07.06.1977.
How can I calculate the days to the next birthday ??


Create timestamps and substract:

<?
echo (strtotime('2004-07-01')-strtotime('1977-07-06')) / 86400;
?>

Where 86400=60*60*24 (seconds/day)
--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2

P: n/a
In article <MP************************@news2.premium-news.de>,
fr***@nettaxi.com says...
Ich want to count the days between the current day an the birthday next
Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday: 07.06.1977.
How can I calculate the days to the next birthday ??


Check out the functions date, getdate and strtotime.

// get timestamp for today
$today_tstamp = date();
// get date array data for today
$today = getdate($today_tstamp);

$bday_string = '1977-07-06';

// get timestamp for birthday
$bday_tstamp = strtotime($bday_string);
// get date array data for birthday
$bday = getdate($bday_tstamp);

// get timestamp for birthday date in this year
$bty_tstamp = strtotime($today[year].'-'.$bday[mon].'-'($bday[mday]);

if ($today_tstamp < $bty_tstamp) {
// birthday not yet happened this year
$bty = getdate($bty_tstamp);
$days_to_party = $bty[yday] - $today[yday]
} else {
// put more stuff here to get timestamp for birth date next year,
// and working out if leap year complications exist, etc.
}

Geoff M
Jul 17 '05 #3

P: n/a
Fraya Pohl wrote:
Ich want to count the days between the current day an the birthday
next Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday:
07.06.1977. How can I calculate the days to the next birthday ??

Please help me !! Thanks Fraya Pohl


<script language="javascript" type="text/javascript">
//<![CDATA[
<!-- Countdown Script by Maxim V. Kollegov -->
<!-- http://www.geocities.com/siliconvalley/lakes/8620 -->
<!-- please keep this comment unchanged if you use it -->
<!-- hide script
//change your event date event here.
var eventdate = new Date("Sep 21, 2011 00:00:00");

function toSt(n)
{s=""
if(n<10) s+="0"
return s+n.toString();
}

function countdown()
{cl=document.clock;
d=new Date();
count=Math.floor((eventdate.getTime()-d.getTime())/1000);
if(count<=0)
{cl.days.value ="----";
cl.hours.value="--";
cl.mins.value="--";
cl.secs.value="--";
return;
}
cl.secs.value=toSt(count%60);
count=Math.floor(count/60);
cl.mins.value=toSt(count%60);
count=Math.floor(count/60);
cl.hours.value=toSt(count%24);
count=Math.floor(count/24);
cl.days.value=count;

setTimeout("countdown()",500);
}
// end script -->
//]]>
</script>

<body bgcolor="#E0E0E0" text="#404040" link="#FF6600" vlink=
"#808080" onload="countdown()">
<form name="clock" action="countdown" id="clock"><font face=
"Times"><b>Nog <input type="text" name="days" size="4" />dagen,
<input type="text" name="hours" size="2" />uren, <input type=
"text" name="mins" size="2" />minuten en <input type="text" name=
"secs" size="2" />seconden,<br />
dan is het 21 september 2011<br />
Die dag is het zeventig jaar geleden dat ik ben
geboren.</b></font></form>

Gerard Schaefers
--
Voor meer kook- en eetplezier? Kijk hier!
http://www.xs4all.nl/~sjeef/Nederlands/Recepten.html
Jul 17 '05 #4

P: n/a
>Ich want to count the days between the current day an the birthday next
Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday: 07.06.1977.
How can I calculate the days to the next birthday ??


Using the example above, what is the correct answer?

I claim the answer is 4 (Jul 2, Jul 3, Jul 4, and Jul 5 are between
Jul 1 and Jul 6. Neither Jul 1 nor Jul 6 are between Jul 1 and Jul
6).

Some people claim the answer is 5 (obtained by subtracting).

How many days are between today and tomorrow? (I claim 0.)
How many days are between a day and itself? (It sounds stupid, but
the only answer that seems to make sense to me is -1.)

You can convert both dates to a Julian day, subtract, then subtract one.
Take a look at the functions juliantojd() or gregoriantojd(). You
may need to reconfigure PHP to include support for the calendar functions.

Gordon L. Burditt
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.