Page 1 of 1
How do you know the following day?
Posted: Wed Jun 27, 2012 10:00 am
by simonmlewis
We have a calendar system and need to show all dates in a month.
I know how to make it display a given date from a database - but if I said $firstdate = "2012-07-01", how do I then use a counter to add one to it - to make it shows "2012-07-02".... and add one again... and so on.
I can query at each stage if the date is valid (ie. if it is 31 June 2012, which doesn't exist).
Hope someone can help. I have a feeling it's to do with turning the date into something else first, and then turning it back into a date format..... but that's all.
Thanks in advance.
Re: How do you know the following day?
Posted: Wed Jun 27, 2012 10:45 am
by Celauran
Re: How do you know the following day?
Posted: Wed Jun 27, 2012 11:04 am
by simonmlewis
Thanks.
Here's my problem so far....(or opportunity!!)
Code: Select all
$postdate = "$year-$month-01";
$checkmth = $month;
while($checkmth == $month)
{
$addmth = substr("$postdate", -5, 2);
$addday = substr("$postdate", -2, 2);
$addyr = substr("$postdate", -11, 4);
$h2 = mktime(0, 0, 0, $addmth, $addday, $addyr);
$d2 = date("F dS, Y", $h) ;
$w2= date("l", $h) ;
echo "<br/>$w2 ";
$postdate = strtotime($postdate);
echo date("d M Y", $postdate);
$postdate = strtotime(date("Y-m-d", strtotime($postdate)) . " +1 day");
$postdate = date("Y-m-d", $postdate);
echo "$postdate";
$checkmth = substr("$postdate", -5, 2);
}
This however produces:
[text]Thursday 01 Jun 20121970-01-02[/text]
It won't add one date to the overall date.
If I can get it to go to 2012-06-02..... I'm onto a winner.
Re: How do you know the following day?
Posted: Wed Jun 27, 2012 12:47 pm
by Celauran
Code: Select all
<?php
$year = '2012';
$month = '06';
$day = '01';
$date = new DateTime("{$year}-{$month}-{$day}");
echo $date->modify('+1 day')->format('Y-m-d');
Re: How do you know the following day?
Posted: Thu Jun 28, 2012 5:41 am
by simonmlewis
Ok I've sorted that bit. Now I have to show times of each day, and if an override is set, only show certain times.
For now, I am showing ALL times, but it won't loop. I don't want to write a full script for each time in the day, so want to loop and at each Counted number, display and query on a time.
Code: Select all
$resultdisable = mysql_query ("SELECT * FROM diaryoverride WHERE dateoverride = '$postdate'")or die(mysql_error());
$num_overrides = mysql_num_rows($resultdisable);
if ($num_overrides == 0)
{
$count = 1;
$totalcount = "2";
if ($count == "1") { $time = "1000";}
if ($count == "2") { $time = "1230";}
while ($count != $totalcount)
{
echo "<tr><td nowrap>$w2 ";
$postdate = strtotime($postdate);
echo date("d M Y", $postdate);
echo "</td>";
echo "<td style='border: 1px solid #000000'>$time $count</td></tr>";
$count = $count + 1;
}
}
This just produces 1000 only. What am I doing wrong? Why won't it then go to 1230?
Re: How do you know the following day?
Posted: Thu Jun 28, 2012 8:20 am
by Celauran
Same principle, just use +30 minutes instead of +1 day.
Re: How do you know the following day?
Posted: Thu Jun 28, 2012 2:29 pm
by simonmlewis
Thanks, tho I cannot do it like that as some of the times are not split perfect. ie, 1000, 1130, 1300, 1400, 1630.....
But I think I have it now. I did it by fluke in the end! lol Added the code, and somehow it worked.