PDA

View Full Version : How to print something according to date's name and number of month ?


jesica
07-13-2008, 05:40 PM
Hello dear fellows,

am trying to use some of the php's date function( date("Y/m/d"); ) in order to print according to current date - name of the day and month in terms of number - something that this day has to be done by the user .

Par example i tried something like this one :


<?

$writingdate=date("D");

if ($writingdate=="Mon" $writingmonth=="01")

echo "Today you have to buy that black label !";

elseif ($writingdate=="Thu" $writingmonth=="02")

echo "Today you have to buy that red label";

else

echo "Today you aint to buy for nothing";

?>

But no success can you help me so to be able to "extract" everyday the date-name and months number ?

thanks in advance :rolleyes:

_Aerospace_Eng_
07-13-2008, 06:40 PM
You aren't using any operators and you should be
<?php

$writingdate=date("D");

if ($writingdate=="Mon" && $writingmonth=="01")

echo "Today you have to buy that black label !";

elseif ($writingdate=="Thu" && $writingmonth=="02")

echo "Today you have to buy that red label";

else

echo "Today you aint to buy for nothing";

?>
Where is $writingmonth coming from?

jesica
07-13-2008, 06:51 PM
Hello Aerospace,

i forgot to add an "m" into the date function using an other var,

so :

<?php

$writingdate=date("D");
$writingmonth=date("m");

if ($writingdate=="Mon" && $writingmonth=="01")

echo "Today you have to buy that black label !";

elseif ($writingdate=="Sun" && $writingmonth=="13")

echo "Today you have to buy that red label";

else

echo "Today you aint to buy for nothing";

?>

But again for the Sun 13 am getting no echo, just is printing the last echo "Today you aint to buy for nothing" hm ..:confused:

jesica
07-13-2008, 06:55 PM
Sily mistake
here is the working one :

<?php

$writingdate=date("D");
$writingmonth=date("m");

if ($writingdate=="Mon" && $writingmonth=="01")

echo "Today you have to buy that black label !";

elseif ($writingdate=="Sun" && $writingmonth=="07")

echo "Today you have to buy that red label";

else

echo "Today you aint to buy for nothing";

?>

Solved is ok now :)

Just a small question +
this one with switch why dosent print anything ?
<?
$writingdate = date("D F");
switch ($writingdate)
{
case '13 July':
echo "Buy black label";
case '13 Oct':
echo "Buy yellow label";
break;
}
?>